CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SoftConversionTrackCandidateProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <memory>
4 
5 // Framework
12 //
17 //
19 //
21 // Abstract classes for the conversion tracking components
24 //
28 
33 #include "Math/GenVector/VectorUtil.h"
34 // Class header file
36 
37 bool IsGoodSeed(const TrajectorySeedCollection& seeds, const TrajectorySeed& seed){
38 
39  // This function is not satisfactory. I don't know how to check equality of TrajectorySeed
40  // So I compare all possible quantities in them.
41  // This function can be dropped when I find to check equality of TrajectorySeed.
42 
43  bool found = false;
44  for(TrajectorySeedCollection::const_iterator it = seeds.begin(); it != seeds.end(); it++){
45  if(it->nHits() != seed.nHits()) continue;
46  if(it->startingState().detId() != seed.startingState().detId()) continue;
47  if(it->startingState().surfaceSide() != seed.startingState().surfaceSide()) continue;
48  if((it->startingState().parameters().position() - seed.startingState().parameters().position()).mag() > 1.0e-6) continue;
49  if((it->startingState().parameters().momentum() - seed.startingState().parameters().momentum()).mag() > 1.0e-6) continue;
50  found = true;
51  break;
52  }
53 
54  return found;
55 }
56 
58  conf_(config),
59  theNavigationSchool_(0),
60  theOutInSeedFinder_(0),
61  theOutInTrackFinder_(0),
62  theInOutSeedFinder_(0),
63  theInOutTrackFinder_(0)
64 {
65  LogDebug("SoftConversionTrackCandidateProducer") << "SoftConversionTrackCandidateProducer CTOR " << "\n";
66 
67  clusterType_ = conf_.getParameter<std::string>("clusterType");
68  clusterBarrelCollection_ = conf_.getParameter<edm::InputTag>("clusterBarrelCollection");
69  clusterEndcapCollection_ = conf_.getParameter<edm::InputTag>("clusterEndcapCollection");
70 
71  OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
72  InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
73 
74  OutInTrackClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateClusterAssociationCollection");
75  InOutTrackClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateClusterAssociationCollection");
76 
77  // Register the product
78  produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
79  produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
80  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackClusterAssociationCollection_);
81  produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackClusterAssociationCollection_);
82 
83 }
84 
86 
88  theOutInSeedFinder_->setEventSetup(theEventSetup);
89  theInOutSeedFinder_->setEventSetup(theEventSetup);
90  theOutInTrackFinder_->setEventSetup(theEventSetup);
91  theInOutTrackFinder_->setEventSetup(theEventSetup);
92 }
93 
94 
95 
97  nEvt_=0;
98  //get magnetic field
99  edm::LogInfo("SoftConversionTrackCandidateProducer") << " get magnetic field" << "\n";
100 
102  theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
104 
105  // get the Out In Seed Finder
106  edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the OutInSeedFinder" << "\n";
108 
109  // get the Out In Track Finder
110  edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the OutInTrackFinder" << "\n";
111  theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_ );
112 
113  // get the In Out Seed Finder
114  edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the InOutSeedFinder" << "\n";
116 
117  // get the In Out Track Finder
118  edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the InOutTrackFinder" << "\n";
119  theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_ );
120 }
121 
123  delete theOutInSeedFinder_;
124  delete theOutInTrackFinder_;
125  delete theInOutSeedFinder_;
126  delete theInOutTrackFinder_;
127 }
128 
129 
131 
132  using namespace edm;
133  nEvt_++;
134  edm::LogInfo("SoftConversionTrackCandidateProducer") << "SoftConversionTrackCandidateProducer Analyzing event number: " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
135 
136  std::cout << "SoftConversionTrackCandidateProducer Analyzing event number: " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
137 
138  setEventSetup( theEventSetup );
139  theOutInSeedFinder_->setEvent(theEvent);
140  theInOutSeedFinder_->setEvent(theEvent);
141  theOutInTrackFinder_->setEvent(theEvent);
142  theInOutTrackFinder_->setEvent(theEvent);
143 
144  // Set the navigation school
146 
147  // collections to be stored in events
148  std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection);
149  std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection);
150  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
151  std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
152 
153  std::vector<edm::Ptr<reco::CaloCluster> > vecOfClusterRefForOutIn;
154  std::vector<edm::Ptr<reco::CaloCluster> > vecOfClusterRefForInOut;
155 
156  // Get the basic cluster collection in the Barrel
157  edm::Handle<edm::View<reco::CaloCluster> > clusterBarrelHandle;
158  theEvent.getByLabel(clusterBarrelCollection_, clusterBarrelHandle);
159 
160  if (!clusterBarrelHandle.isValid()) {
161  edm::LogError("SoftConverionTrackCandidateProducer") << "Error! Can't get the product "<<clusterBarrelCollection_.label();
162  return;
163  }
164 
165  buildCollections(clusterBarrelHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, vecOfClusterRefForOutIn, vecOfClusterRefForInOut);
166 
167  if(clusterType_ == "BasicCluster" ) {
168  // Get the basic cluster collection in the Endcap
169  edm::Handle<edm::View<reco::CaloCluster> > clusterEndcapHandle;
170  theEvent.getByLabel(clusterEndcapCollection_, clusterEndcapHandle);
171 
172  if (!clusterEndcapHandle.isValid()) {
173  edm::LogError("SoftConversionTrackCandidateProducer") << "Error! Can't get the product "<<clusterEndcapCollection_.label();
174  return;
175  }
176 
177  buildCollections(clusterEndcapHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, vecOfClusterRefForOutIn, vecOfClusterRefForInOut);
178 
179  }
180 
181  // put all products in the event
182  const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
183  const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
184 
185  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
186  fillerOI.insert(refprodOutInTrackC, vecOfClusterRefForOutIn.begin(), vecOfClusterRefForOutIn.end());
187  fillerOI.fill();
188  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
189  fillerIO.insert(refprodInOutTrackC, vecOfClusterRefForInOut.begin(), vecOfClusterRefForInOut.end());
190  fillerIO.fill();
191 
192  theEvent.put( outInAssoc_p, OutInTrackClusterAssociationCollection_);
193  theEvent.put( inOutAssoc_p, InOutTrackClusterAssociationCollection_);
194 }
195 
196 
198  TrackCandidateCollection& outInTrackCandidates,
199  TrackCandidateCollection& inOutTrackCandidates,
200  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
201  std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO) {
202 
203  // temporary collection
204  TrackCandidateCollection tempTCC;
205  TrajectorySeedCollection totalOISeeds; // total number of out-in trajectory seeds through entire cluster collection loop
206  TrajectorySeedCollection totalIOSeeds; // total number of in-out trajectory seeds through entire cluster collection loop
207 
208  int nClusters = (int) clusterHandle->size();
209 
210  // first loop to fill totalOISeeds and totalIOSeeds
211 
212  for(int iCluster=0; iCluster<nClusters; iCluster++){
213  reco::CaloClusterPtr clusterRefOutIn = clusterHandle->ptrAt(iCluster);
214  math::XYZPoint position = clusterRefOutIn->position();
215  GlobalPoint gp(position.x(),position.y(),position.z());
216  theOutInSeedFinder_->setCandidate(clusterRefOutIn->energy(),gp);
217  theOutInSeedFinder_->makeSeeds(clusterRefOutIn);
218 
219 
221  for(TrajectorySeedCollection::const_iterator it = oISeeds.begin(); it != oISeeds.end(); it++){
222  totalOISeeds.push_back(*it);
223  }
224 
225  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(oISeeds, tempTCC);
226  tempTCC.clear();
227 
228  for(int jCluster=iCluster; jCluster<nClusters; jCluster++){
229  reco::CaloClusterPtr clusterRefInOut = clusterHandle->ptrAt(jCluster);
230 
231  math::XYZPoint position2 = clusterRefInOut->position();
232  GlobalPoint gp2(position2.x(),position2.y(),position2.z());
233  double dEta = std::abs(position.Eta() - position2.Eta());
234  if(dEta > 0.1) continue;
235 
236  double dPhi = std::abs(ROOT::Math::VectorUtil::DeltaPhi(position, position2));
237  if(dPhi > 0.5) continue;
238 
239  theInOutSeedFinder_->setCandidate(clusterRefInOut->energy(),gp2);
240  theInOutSeedFinder_->setTracks(theOutInTracks);
241  theInOutSeedFinder_->makeSeeds(clusterHandle);
242 
244 
245  for(TrajectorySeedCollection::const_iterator it = iOSeeds.begin(); it != iOSeeds.end(); it++){
246  totalIOSeeds.push_back(*it);
247  }
248 
249  }// for jCluster
250  }// for iCluster
251 
252 
253  // Now we have total OI/IO seeds. Let's clean them up and save them with only giving good trajectories
254  TrajectorySeedCollection oIFilteredSeeds;
255  TrajectorySeedCollection iOFilteredSeeds;
256 
257  tempTCC.clear();
258  std::vector<Trajectory> tempTrj = theOutInTrackFinder_->tracks(totalOISeeds,tempTCC);
259  for(std::vector<Trajectory>::iterator it = tempTrj.begin(); it!= tempTrj.end(); it++){
260  oIFilteredSeeds.push_back(it->seed());
261  }
262 
263  tempTrj.clear();
264  tempTCC.clear();
265  tempTrj = theInOutTrackFinder_->tracks(totalIOSeeds,tempTCC);
266  for(std::vector<Trajectory>::iterator it = tempTrj.begin(); it!= tempTrj.end(); it++){
267  iOFilteredSeeds.push_back(it->seed());
268  }
269 
270  tempTCC.clear();
271  tempTrj.clear();
272  totalOISeeds.clear();
273  totalIOSeeds.clear();
274 
275 
276  // Now start normal procedure and consider seeds that belong to filtered ones.
277 
278  for(int iCluster=0; iCluster<nClusters; iCluster++){
279  reco::CaloClusterPtr clusterRefOutIn = clusterHandle->ptrAt(iCluster);
280  math::XYZPoint position = clusterRefOutIn->position();
281  GlobalPoint gp(position.x(),position.y(),position.z());
282  theOutInSeedFinder_->setCandidate(clusterRefOutIn->energy(),gp);
283  theOutInSeedFinder_->makeSeeds(clusterRefOutIn);
284 
286  TrajectorySeedCollection oISeeds;
287  for(TrajectorySeedCollection::iterator it = oISeeds_all.begin(); it != oISeeds_all.end(); it++){
288  if(IsGoodSeed(oIFilteredSeeds,*it)) oISeeds.push_back(*it);
289  }
290 
291  if(oISeeds.size() == 0) continue;
292 
293  std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(oISeeds, outInTrackCandidates);
294 
295  int nOITrj = (int) theOutInTracks.size();
296  for(int itrj=0; itrj < nOITrj; itrj++) vecRecOI.push_back( clusterRefOutIn );
297 
298  for(int jCluster=iCluster; jCluster<nClusters; jCluster++){
299  reco::CaloClusterPtr clusterRefInOut = clusterHandle->ptrAt(jCluster);
300 
301  math::XYZPoint position2 = clusterRefInOut->position();
302  GlobalPoint gp2(position2.x(),position2.y(),position2.z());
303  double dEta = std::abs(position.Eta() - position2.Eta());
304  if(dEta > 0.1) continue;
305 
306  double dPhi = std::abs(ROOT::Math::VectorUtil::DeltaPhi(position, position2));
307  if(dPhi > 0.5) continue;
308 
309  theInOutSeedFinder_->setCandidate(clusterRefInOut->energy(),gp2);
310  theInOutSeedFinder_->setTracks(theOutInTracks);
311  theInOutSeedFinder_->makeSeeds(clusterHandle);
312 
314  TrajectorySeedCollection iOSeeds;
315  for(TrajectorySeedCollection::iterator it = iOSeeds_all.begin(); it != iOSeeds_all.end(); it++){
316  if(IsGoodSeed(iOFilteredSeeds,*it)) iOSeeds.push_back(*it);
317  }
318 
319  if(iOSeeds.size() == 0) continue;
320 
321  std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(iOSeeds, inOutTrackCandidates);
322 
323  int nIOTrj = (int) theInOutTracks.size();
324  for(int itrj=0; itrj < nIOTrj; itrj++) vecRecIO.push_back( clusterRefInOut );
325 
326  }// for jCluster
327  }// for iCluster
328 
329 
330 }
331 
#define LogDebug(id)
void buildCollections(const edm::Handle< edm::View< reco::CaloCluster > > &clusterHandle, TrackCandidateCollection &outInTracks, TrackCandidateCollection &inOutTracks, std::vector< edm::Ptr< reco::CaloCluster > > &vecRecOI, std::vector< edm::Ptr< reco::CaloCluster > > &vecRecIO)
T getParameter(std::string const &) const
void setTracks(std::vector< Trajectory > in)
LocalPoint position() const
Local x and y position coordinates.
std::vector< TrackCandidate > TrackCandidateCollection
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
#define abs(x)
Definition: mlp_lapack.h:159
TrajectorySeedCollection seeds()
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection seeds, TrackCandidateCollection &candidate) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual void endRun(edm::Run &r, edm::EventSetup const &es)
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
std::vector< TrajectorySeed > TrajectorySeedCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void setEvent(const edm::Event &e)
virtual void makeSeeds(const edm::Handle< edm::View< reco::CaloCluster > > &allBc) const
LocalVector momentum() const
Momentum vector in the local frame.
bool isValid() const
Definition: HandleBase.h:76
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
const int surfaceSide() const
PTrajectoryStateOnDet const & startingState() const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
void setEvent(const edm::Event &e)
const T & get() const
Definition: EventSetup.h:55
const unsigned int detId() const
T const * product() const
Definition: ESHandle.h:62
virtual void setCandidate(float e, GlobalPoint pos) const
bool IsGoodSeed(const TrajectorySeedCollection &seeds, const TrajectorySeed &seed)
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
std::string const & label() const
Definition: InputTag.h:25
edm::EventID id() const
Definition: EventBase.h:56
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection seeds, TrackCandidateCollection &candidates) const
unsigned int nHits() const
tuple config
Definition: cmsDriver.py:17
tuple cout
Definition: gather_cfg.py:41
virtual void beginRun(edm::Run &r, edm::EventSetup const &es)
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
virtual void makeSeeds(const edm::Handle< edm::View< reco::CaloCluster > > &allBc) const
const LocalTrajectoryParameters & parameters() const
Definition: Run.h:31