ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerDecayParts.cc
Revision: 1.11
Committed: Thu Oct 16 16:17:17 2008 UTC (16 years, 6 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_005
Changes since 1.10: +43 -22 lines
Log Message:
Moved HitPattern parsing to a seperate class with more checks and now compatible with fixed hit layer mask format

File Contents

# User Rev Content
1 bendavid 1.11 // $Id: FillerDecayParts.cc,v 1.10 2008/10/13 10:41:59 bendavid Exp $
2 paus 1.1
3 loizides 1.4 #include "MitAna/DataTree/interface/DecayParticle.h"
4 bendavid 1.6 #include "MitAna/DataTree/interface/DaughterData.h"
5 paus 1.1 #include "FWCore/MessageLogger/interface/MessageLogger.h"
6 bendavid 1.10 #include "FWCore/Framework/interface/ESHandle.h"
7 paus 1.1 #include "DataFormats/Common/interface/Handle.h"
8     #include "DataFormats/TrackReco/interface/Track.h"
9     #include "DataFormats/TrackReco/interface/TrackFwd.h"
10 bendavid 1.10 #include "DataFormats/TrackReco/interface/HitPattern.h"
11     #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
12 paus 1.1 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
13     #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
14     #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
15 loizides 1.8 #include "MitEdm/DataFormats/interface/Collections.h"
16 bendavid 1.2 #include "MitEdm/DataFormats/interface/DecayPart.h"
17     #include "MitEdm/DataFormats/interface/BasePart.h"
18     #include "MitEdm/DataFormats/interface/BasePartFwd.h"
19 paus 1.1 #include "MitProd/TreeFiller/interface/FillerDecayParts.h"
20     #include "MitAna/DataTree/interface/Names.h"
21    
22     using namespace std;
23     using namespace edm;
24     using namespace mithep;
25    
26     //--------------------------------------------------------------------------------------------------
27 loizides 1.4 FillerDecayParts::FillerDecayParts(const ParameterSet &cfg, const char *name, bool active) :
28 paus 1.1 BaseFiller(cfg,name,active),
29 loizides 1.4 edmName_(Conf().getUntrackedParameter<string>("edmName","")),
30     mitName_(Conf().getUntrackedParameter<string>("mitName","")),
31 bendavid 1.9 vertexMapName_(Conf().getUntrackedParameter<string>("vertexMap","")),
32 loizides 1.8 basePartMapNames_(Conf().exists("basePartMaps") ?
33     Conf().getUntrackedParameter<vector<string> >("basePartMaps") :
34     vector<string>()),
35 bendavid 1.9 vertexMap_(0),
36     decays_(new mithep::DecayParticleArr(250)),
37     stableData_(new mithep::StableDataArr(500)),
38     decayData_(new mithep::DecayDataArr(500))
39 paus 1.1 {
40 loizides 1.4 // Constructor.
41 paus 1.1 }
42    
43     //--------------------------------------------------------------------------------------------------
44     FillerDecayParts::~FillerDecayParts()
45     {
46 loizides 1.4 // Destructor.
47    
48 paus 1.1 delete decays_;
49 bendavid 1.9 delete stableData_;
50     delete decayData_;
51 paus 1.1 }
52    
53     //--------------------------------------------------------------------------------------------------
54     void FillerDecayParts::BookDataBlock(TreeWriter &tws)
55     {
56 loizides 1.4 // Add tracks branch to tree and get our map.
57 bendavid 1.9 std::string stableDataName = mitName_ + "_StableDatas";
58     std::string decayDataName = mitName_ + "_DecayDatas";
59    
60     tws.AddBranch(mitName_.c_str(),&decays_);
61     tws.AddBranch(stableDataName.c_str(), &stableData_);
62     tws.AddBranch(decayDataName.c_str(), &decayData_);
63 loizides 1.4
64 bendavid 1.9 if (!vertexMapName_.empty())
65     vertexMap_ = OS()->get<VertexMap>(vertexMapName_.c_str());
66    
67 bendavid 1.6 for (std::vector<std::string>::const_iterator bmapName = basePartMapNames_.begin();
68     bmapName!=basePartMapNames_.end(); ++bmapName) {
69     if (!bmapName->empty())
70     basePartMaps_.push_back(OS()->get<BasePartMap>(bmapName->c_str()));
71     }
72 paus 1.1 }
73    
74     //--------------------------------------------------------------------------------------------------
75     void FillerDecayParts::FillDataBlock(const edm::Event &evt,
76     const edm::EventSetup &setup)
77     {
78 loizides 1.4 // Fill our EDM DecayPart collection into the MIT DecayParticle collection.
79 paus 1.1 decays_->Reset();
80 bendavid 1.9 stableData_->Reset();
81     decayData_->Reset();
82 loizides 1.4
83 bendavid 1.2 Handle<mitedm::DecayPartCol> hParts;
84 paus 1.1 GetProduct(edmName_, hParts, evt);
85 bendavid 1.2 const mitedm::DecayPartCol *iParts = hParts.product();
86 paus 1.1
87     // loop through all decayParts and fill the information
88 bendavid 1.2 for (UInt_t i=0; i<iParts->size(); ++i) {
89     const mitedm::DecayPart &p =iParts->at(i); // for convenience
90     mithep::DecayParticle *d = decays_->Allocate();
91 bendavid 1.9 new (d) mithep::DecayParticle(p.pid());
92 bendavid 1.2
93 bendavid 1.9 d->SetMassError(p.fittedMassError());
94     d->SetLxy(p.lxyToPv());
95     d->SetLxyError(p.lxyToPvError());
96     d->SetDxy(p.dxyToPv());
97     d->SetDxyError(p.dxyToPvError());
98     d->SetLz(p.lzToPv());
99     d->SetLzError(p.lzToPvError());
100 bendavid 1.2 d->SetMom(p.fourMomentum());
101 mrudolph 1.5 d->SetChi2(p.chi2());
102     d->SetNdof(p.ndof());
103 bendavid 1.10
104     if (p.primaryVertex().isNonnull()) {
105 bendavid 1.9 d->SetPriVertex(vertexMap_->GetMit(p.primaryVertex()));
106 bendavid 1.10 }
107    
108 bendavid 1.6 if (basePartMaps_.size()) {
109 bendavid 1.9 //loop through and add stable daughters
110     for (Int_t j=0; j<p.nStableChild(); ++j) {
111     const mitedm::StableData &stable = p.getStableData(j);
112     mitedm::BasePartPtr thePtr = stable.originalPtr();
113     mithep::Particle *daughter = getMitParticle(thePtr);
114    
115     mithep::StableData *outStable = stableData_->Allocate();
116     new (outStable) mithep::StableData(daughter,stable.p3().x(),stable.p3().y(),stable.p3().z());
117 bendavid 1.6
118 bendavid 1.11 //fill bad layer mask information using corrected HitPattern
119     const ChargedParticle *cDaughter = dynamic_cast<const ChargedParticle*>(daughter);
120     if (cDaughter) {
121     const reco::HitPattern &hitPattern = stable.Hits();
122     BitMask64 crossedLayers;
123     UInt_t numCrossed=0;
124     //search for all good crossed layers (with or without hit)
125     for (Int_t hi=0; hi<hitPattern.numberOfHits(); hi++) {
126     uint32_t hit = hitPattern.getHitPattern(hi);
127     if (hitPattern.getHitType(hit)<=1)
128     if (hitPattern.trackerHitFilter(hit)) {
129     numCrossed++;
130     crossedLayers.SetBit(hitReader_.Layer(hit));
131     }
132     }
133     BitMask64 badLayers = crossedLayers ^ cDaughter->Trk()->Hits();
134     outStable->SetBadLayers(badLayers);
135    
136     // if (outStable->NWrongHits()) {
137     // printf("numCrossed: %i\n",numCrossed);
138     // printf("Hit Pattern Size: %i\n",hitPattern.numberOfHits());
139     // printf("# of hits: %i\n",cDaughter->Trk()->NHits());
140     // printf("# of crossed layers: %i\n",crossedLayers.NBitsSet());
141     // printf("# of wrong/missing layers: %i\n",badLayers.NBitsSet());
142     // printf("# of missed hits: %i\n",outStable->NMissedHits());
143     // printf("# of wrong hits: %i\n",outStable->NWrongHits());
144     // printf("Hits : ");
145     // for (Int_t biti=63; biti >= 0; --biti) {
146     // printf("%i",cDaughter->Trk()->Hits().TestBit(biti));
147     // }
148     // printf("\n");
149     // printf("Crossed Layers : ");
150     // for (Int_t biti=63; biti >= 0; --biti) {
151     // printf("%i",crossedLayers.TestBit(biti));
152     // }
153     // printf("\n");
154     // printf("WrongOrMissingHits: ");
155     // for (Int_t biti=63; biti>=0; --biti) {
156     // printf("%i",badLayers.TestBit(biti));
157     // }
158     // printf("\n");
159     // }
160 bendavid 1.10 }
161    
162 bendavid 1.9 d->AddDaughterData(outStable);
163 bendavid 1.10
164 bendavid 1.9 }
165     //loop through and add decay daughters
166     for (Int_t j=0; j<p.nDecayChild(); ++j) {
167     const mitedm::DecayData &decay = p.getDecayData(j);
168     mitedm::BasePartPtr thePtr = decay.originalPtr();
169     mithep::Particle *daughter = getMitParticle(thePtr);
170    
171     mithep::DecayData *outDecay = decayData_->Allocate();
172     new (outDecay) mithep::DecayData(daughter,decay.p4());
173     outDecay->SetMassError(decay.massErr());
174     outDecay->SetLxy(decay.lxy());
175     outDecay->SetLxyError(decay.lxyErr());
176     outDecay->SetLz(decay.lz());
177     outDecay->SetLzError(decay.lzErr());
178     outDecay->SetDxy(decay.dxy());
179     outDecay->SetDxyError(decay.dxyErr());
180    
181     d->AddDaughterData(outDecay);
182 bendavid 1.2 }
183     }
184 paus 1.1 }
185     decays_->Trim();
186 bendavid 1.9 stableData_->Trim();
187     decayData_->Trim();
188     }
189    
190     //--------------------------------------------------------------------------------------------------
191     mithep::Particle *FillerDecayParts::getMitParticle(mitedm::BasePartPtr ptr) const
192     {
193     mithep::Particle *mitPart = 0;
194     for (std::vector<const mithep::BasePartMap*>::const_iterator bmap = basePartMaps_.begin();
195     bmap!=basePartMaps_.end(); ++bmap) {
196     const mithep::BasePartMap *theMap = *bmap;
197     if (theMap->HasMit(ptr))
198     mitPart = theMap->GetMit(ptr);
199     }
200    
201     if (!mitPart)
202     throw edm::Exception(edm::errors::Configuration, "FillerDecayParts::FillDataBlock()\n")
203     << "Error! MITHEP Object "
204     << "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
205    
206     return mitPart;
207 paus 1.1 }