ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Morgan/src/MuonAnalyzer.cc
(Generate patch)

Comparing UserCode/Morgan/src/MuonAnalyzer.cc (file contents):
Revision 1.7 by lethuill, Thu Apr 9 16:55:09 2009 UTC vs.
Revision 1.14 by lethuill, Wed Jun 10 11:17:06 2009 UTC

# Line 4 | Line 4 | using namespace std;
4   using namespace reco;
5   using namespace edm;
6  
7 < MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames):verbosity_(0),useMC_(false)
7 > MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):LeptonAnalyzer(producersNames, myConfig, verbosity)
8   {
9        dataType_ = producersNames.getUntrackedParameter<string>("dataType","unknown");
10        muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
11 }
12
13 MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity):verbosity_(verbosity)
14 {
15        dataType_ = producersNames.getUntrackedParameter<string>("dataType","unknown");
16        muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
9          useMC_ = myConfig.getUntrackedParameter<bool>("doMuonMC");
10 +        muonProducer_ = producersNames.getParameter<edm::InputTag>("muonProducer");
11   }
12  
13   MuonAnalyzer::~MuonAnalyzer()
14   {
15   }
16  
17 < void MuonAnalyzer::Process(const edm::Event& iEvent, TClonesArray* rootMuons)
17 > bool MuonAnalyzer::process(const edm::Event& iEvent, TRootBeamSpot* rootBeamSpot, TClonesArray* rootMuons)
18   {
19  
20          Float_t sintheta = 0.;
21          unsigned int nMuons=0;
22  
23          edm::Handle < std::vector <reco::Muon> > recoMuons;
24 <        if( dataType_=="RECO" || dataType_=="AOD" )
24 >        if( dataType_=="RECO" )
25          {
26 <                iEvent.getByLabel(muonProducer_, recoMuons);
27 <                nMuons = recoMuons->size();
26 >      try
27 >      {
28 >         iEvent.getByLabel(muonProducer_, recoMuons);
29 >         nMuons = recoMuons->size();
30 >      }
31 >      catch (cms::Exception& exception)
32 >      {
33 >         if ( !allowMissingCollection_ )
34 >         {
35 >            cout << "  ##### ERROR IN  MuonAnalyzer::process => reco::Muon collection is missing #####"<<endl;
36 >            throw exception;
37 >         }
38 >         if(verbosity_>1) cout <<  "   ===> No reco::Muon collection, skip muon info" << endl;
39 >         return false;
40 >      }
41          }
42  
43          edm::Handle < std::vector <pat::Muon> > patMuons;
44 <        if( dataType_=="PAT" || dataType_=="PATAOD" )
44 >        if( dataType_=="PAT" )
45          {
46 <                iEvent.getByLabel(muonProducer_, patMuons);
47 <                nMuons = patMuons->size();
46 >      try
47 >      {
48 >         iEvent.getByLabel(muonProducer_, patMuons);
49 >         nMuons = patMuons->size();
50 >      }
51 >      catch (cms::Exception& exception)
52 >      {
53 >         if ( !allowMissingCollection_ )
54 >         {
55 >            cout << "  ##### ERROR IN  MuonAnalyzer::process => pat::Muon collection is missing #####"<<endl;
56 >            throw exception;
57 >         }
58 >         if(verbosity_>1) cout <<  "   ===> No pat::Muon collection, skip muon info" << endl;
59 >         return false;
60 >      }
61          }
62  
63          if(verbosity_>1) std::cout << "   Number of muons = " << nMuons << "   Label: " << muonProducer_.label() << "   Instance: " << muonProducer_.instance() << std::endl;
# Line 46 | Line 65 | void MuonAnalyzer::Process(const edm::Ev
65          for (unsigned int j=0; j<nMuons; j++)
66          {
67                  const reco::Muon* muon = 0;    
68 <                if( dataType_=="RECO" || dataType_=="AOD" ) muon =  &((*recoMuons)[j]);
69 <                if( dataType_=="PAT" || dataType_=="PATAOD" ) muon = (const reco::Muon*) ( & ((*patMuons)[j]) );
68 >                if( dataType_=="RECO" ) muon =  &((*recoMuons)[j]);
69 >                if( dataType_=="PAT" ) muon = (const reco::Muon*) ( & ((*patMuons)[j]) );
70  
71                  TRootMuon localMuon(
72                          muon->px()
# Line 111 | Line 130 | void MuonAnalyzer::Process(const edm::Ev
130                  );
131  
132                  // Variables from reco::Track
133 +                
134 +                // Track in muon detector only
135 +                reco::TrackRef outerTK = muon->outerTrack();
136 +                if ( outerTK.isNonnull() )
137 +                {
138 +                        //cout << "outerTK (px,py,pz)=" << outerTK->px() <<" , " << outerTK->py() <<" , " << outerTK->pz() <<" )" << endl;
139 +                        localMuon.setXYZTOuterTrack( outerTK->px(), outerTK->py(), outerTK->pz(), outerTK->p() );
140 +                }
141 +
142 +                // Track in tracker + muon detector
143 +                reco::TrackRef globalTK = muon->globalTrack();
144 +                if ( globalTK.isNonnull() )
145 +                {
146 +                        //cout << "globalTK (px,py,pz)=" << globalTK->px() <<" , " << globalTK->py() <<" , " << globalTK->pz() <<" )" << endl;
147 +                        localMuon.setXYZTGlobalTrack( globalTK->px(), globalTK->py(), globalTK->pz(), globalTK->p() );
148 +                }
149 +
150 +                // Track in tracker only
151                  reco::TrackRef track = muon->innerTrack();
152                  if ( track.isNonnull() )
153                  {
154 +                        //cout << "innerTK (px,py,pz)=" << track->px() <<" , " << track->py() <<" , " << track->pz() <<" )" << endl;
155 +                        localMuon.setXYZTInnerTrack( track->px(), track->py(), track->pz(), track->p() );
156                          const reco::HitPattern& hit = track->hitPattern();
157                          localMuon.setNumberOfValidPixelHits(hit.numberOfValidPixelHits());
158                          localMuon.setNumberOfValidTrackerHits(hit.numberOfValidTrackerHits());
159 <                        // FIXME - replace with double dxy(const Point& myBeamSpot) method ?
160 <                        localMuon.setD0(track->d0());
159 >                        localMuon.setPixelLayersWithMeasurement(hit.pixelLayersWithMeasurement());
160 >                        localMuon.setStripLayersWithMeasurement(hit.stripLayersWithMeasurement());
161 >
162 >                        if (doBeamSpot_)
163 >                        {
164 >                                if ( rootBeamSpot->sigmaZ() > 0. ) // Check beam spot was correctly initialised
165 >                                {
166 >                                        const reco::TrackBase::Point point( rootBeamSpot->x(), rootBeamSpot->y(), rootBeamSpot->z() );
167 >                                        localMuon.setD0( -1.*(track->dxy(point)) );
168 >                                        localMuon.setDsz( track->dsz(point) );
169 >                                }
170 >                                else
171 >                                {
172 >                                        localMuon.setD0( -1.*(track->dxy()) );
173 >                                        localMuon.setDsz( track->dsz() );
174 >                                }
175 >                        }
176 >                        else
177 >                        {
178 >                                localMuon.setD0( -1.*(track->dxy()) );
179 >                                localMuon.setDsz( track->dsz() );
180 >                        }
181 >                        
182                          localMuon.setD0Error(track->d0Error());
123                        // FIXME - replace with double dsz(const Point& myBeamSpot) method ?
124                        localMuon.setDsz(track->dsz());
183                          localMuon.setDszError(track->dszError());
184 +        
185                          localMuon.setNormalizedChi2(track->normalizedChi2());
186                          localMuon.setPtError(track->ptError());
187                          localMuon.setEtaError(track->etaError());
188                          localMuon.setPhiError(track->phiError());
189 +                        
190 +                        if(doPrimaryVertex_)
191 +                        {
192 +                                // FIXME - Should be Tracker track... what if STA muon ?
193 +                                const reco::TransientTrack transtrack = trackBuilder_->build( track ) ;
194 +                                float sig3d = ip3DSignificance(transtrack);
195 +                                //localMuon.setIP3DSignificance(sig3d);
196 +                        }
197                  }
198  
199  
200 <                if( dataType_=="RECO" || dataType_=="AOD" )
200 >                if( dataType_=="RECO" )
201                  {
202                          // Some specific methods requiring  RECO / AOD format
203                          // Do association to genParticle ?
204                          // Add InnerTrack, OuterTrack, GlobalTrack infos ?
205                  }
206  
207 <                if( dataType_=="PATAOD" || dataType_=="PAT" )
207 >                if( dataType_=="PAT" )
208                  {
209                          // Some specific methods to pat::Muon
210                          const pat::Muon *patMuon = dynamic_cast<const pat::Muon*>(&*muon);
211 <                        // Use existing reference to genParticle [ pat::PATObject::genParticleRef() ] ?
211 >         // Use existing reference to genParticle [ pat::PATObject::genParticleRef() ] ?
212                          // Alternative methode for isolation (isoDeposit) ?
213                          //
214                          // leptonID apparently not initialised in PAT...
# Line 161 | Line 228 | void MuonAnalyzer::Process(const edm::Ev
228                  new( (*rootMuons)[j] ) TRootMuon(localMuon);
229                  if(verbosity_>2) cout << "   ["<< setw(3) << j << "] " << localMuon << endl;
230          }
231 +  
232 +   return true;
233   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines