CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCSeedrecHitFinder.cc
Go to the documentation of this file.
1 
10 
11 using namespace std;
12 using namespace edm;
13 
14 
15 // Comparator function must be global function?
16 // Could not be included in .h file, or there will be 2 lessPhi() functions in both RPCSeedGenerator and RPCSeedFinder module
18 {
19  // Don't need to use value() in Geom::Phi to short
20  return (it1->globalPosition().phi() < it2->globalPosition().phi());
21 }
22 
24 
25  // Initiate the member
26  isLayerset = false;
27  isConfigured = false;
28  isInputset = false;
29  isOutputset = false;
30  BxRange = 0;
31  MaxDeltaPhi = 0;
32  ClusterSet.clear();
33  LayersinRPC.clear();
34  therecHits.clear();
35 }
36 
38 
39 }
40 
42 
43  // Set the configuration
44  BxRange = iConfig.getParameter<unsigned int>("BxRange");
45  MaxDeltaPhi = iConfig.getParameter<double>("MaxDeltaPhi");
46  ClusterSet = iConfig.getParameter< std::vector<int> >("ClusterSet");
47 
48  // Set the signal open
49  isConfigured = true;
50 }
51 
53 
54  for(unsigned int i = 0; i < RPCLayerNumber; i++)
55  recHitsRPC[i] = &recHits[i];
56  isInputset = true;
57 }
58 
60 
61  isInputset = false;
62 }
64 
65  theSeed = Seed;
66  isOutputset = true;
67 }
68 
69 void RPCSeedrecHitFinder::setLayers(const std::vector<unsigned int>& Layers) {
70 
71  LayersinRPC = Layers;
72  isLayerset = true;
73 }
74 
76 
77  if(isLayerset == false || isConfigured == false || isOutputset == false || isInputset == false)
78  {
79  cout << "Not set the IO or not configured yet" << endl;
80  return;
81  }
82  cout << "Now fill recHits from Layers: ";
83  for(unsigned int k = 0; k < LayersinRPC.size(); k++)
84  cout << LayersinRPC[k] <<" ";
85  cout << endl;
86  unsigned int LayerIndex = 0;
87  therecHits.clear();
88  complete(LayerIndex);
89 
90  // Unset the signal
91  LayersinRPC.clear();
92  therecHits.clear();
93  isLayerset = false;
94 }
95 
96 void RPCSeedrecHitFinder::complete(unsigned int LayerIndex) {
97 
98  for(MuonRecHitContainer::const_iterator it = recHitsRPC[LayersinRPC[LayerIndex]]->begin(); it != recHitsRPC[LayersinRPC[LayerIndex]]->end(); it++)
99  {
100  cout << "Completing layer[" << LayersinRPC[LayerIndex] << "]." << endl;
101 
102  // Check validation
103  if(!(*it)->isValid())
104  continue;
105 
106  // Check BX range, be sure there is only RPCRecHit in the MuonRecHitContainer when use the dynamic_cast
107  TrackingRecHit* thisTrackingRecHit = (*it)->hit()->clone();
108  // Should also delete the RPCRecHit object cast by dynamic_cast<> ?
109  RPCRecHit* thisRPCRecHit = dynamic_cast<RPCRecHit*>(thisTrackingRecHit);
110  int BX = thisRPCRecHit->BunchX();
111  int ClusterSize = thisRPCRecHit->clusterSize();
112  delete thisTrackingRecHit;
113  // Check BX
114  if((unsigned int)abs(BX) > BxRange)
115  continue;
116  // Check cluster size
117  bool Clustercheck = false;
118  if(ClusterSet.size() == 0)
119  Clustercheck = true;
120  for(std::vector<int>::const_iterator CluIter = ClusterSet.begin(); CluIter != ClusterSet.end(); CluIter++)
121  if(ClusterSize == (*CluIter))
122  Clustercheck = true;
123  if(Clustercheck != true)
124  continue;
125  // Check the recHits Phi range
126  GlobalPoint pos = (*it)->globalPosition();
127  double Phi = pos.phi();
128  cout << "Phi: " << Phi << endl;
129  // The recHits should locate in some phi range
130  therecHits.push_back(*it);
131  double deltaPhi = getdeltaPhifromrecHits();
132  cout << "Delta phi: "<< deltaPhi << endl;
133  therecHits.pop_back();
134  if(deltaPhi > MaxDeltaPhi)
135  continue;
136 
137  // If pass all, add to the seed
138  therecHits.push_back(*it);
139  cout << "RecHit's global position: " << pos.x() << ", " << pos.y() << ", " << pos.z() << endl;
140 
141  // Check if this recHit is the last one in the seed
142  // If it is the last one, calculate the seed
143  if(LayerIndex == (LayersinRPC.size()-1))
144  {
145  cout << "Check and fill one seed." << endl;
146  checkandfill();
147  }
148  // If it is not the last one, continue to fill the seed from other layers
149  else
150  complete(LayerIndex+1);
151 
152  // Remember to pop the recHit before add another one from the same layer!
153  therecHits.pop_back();
154  }
155 }
156 
158 
159  ConstMuonRecHitContainer sortRecHits = therecHits;
160  sort(sortRecHits.begin(), sortRecHits.end(), lessPhi);
161  cout << "Sorted recHit's Phi: ";
162  for(ConstMuonRecHitContainer::const_iterator iter = sortRecHits.begin(); iter != sortRecHits.end(); iter++)
163  cout << (*iter)->globalPosition().phi() << ", ";
164  cout << endl;
165  // Calculate the deltaPhi, take care Geom::Phi always in range [-pi,pi)
166  // In case of some deltaPhi larger then Pi, use value() in Geom::Phi to get the true value in radians of Phi, then do the calculation
167  double deltaPhi = 0;
168  if(sortRecHits.size() <= 1)
169  return deltaPhi;
170  if(sortRecHits.size() == 2)
171  {
172  ConstMuonRecHitContainer::const_iterator iter1 = sortRecHits.begin();
173  ConstMuonRecHitContainer::const_iterator iter2 = sortRecHits.begin();
174  iter2++;
175  deltaPhi = (((*iter2)->globalPosition().phi().value() - (*iter1)->globalPosition().phi().value()) > M_PI) ? (2 * M_PI - ((*iter2)->globalPosition().phi().value() - (*iter1)->globalPosition().phi().value())) : ((*iter2)->globalPosition().phi().value() - (*iter1)->globalPosition().phi().value());
176  return deltaPhi;
177  }
178  else
179  {
180  deltaPhi = 2 * M_PI;
181  int n = 0;
182  for(ConstMuonRecHitContainer::const_iterator iter = sortRecHits.begin(); iter != sortRecHits.end(); iter++)
183  {
184  cout << "Before this loop deltaPhi is " << deltaPhi << endl;
185  n++;
186  double deltaPhi_more = 0;
187  double deltaPhi_less = 0;
188  if(iter == sortRecHits.begin())
189  {
190  cout << "Calculateing frist loop..." << endl;
191  ConstMuonRecHitContainer::const_iterator iter_more = ++iter;
192  --iter;
193  ConstMuonRecHitContainer::const_iterator iter_less = sortRecHits.end();
194  --iter_less;
195  cout << "more_Phi: " << (*iter_more)->globalPosition().phi() << ", less_Phi: " << (*iter_less)->globalPosition().phi() << ", iter_Phi: " << (*iter)->globalPosition().phi() << endl;
196  deltaPhi_more = (2 * M_PI) - ((*iter_more)->globalPosition().phi().value() - (*iter)->globalPosition().phi().value());
197  deltaPhi_less = (*iter_less)->globalPosition().phi().value() - (*iter)->globalPosition().phi().value();
198  }
199  else if(iter == (--sortRecHits.end()))
200  {
201  cout << "Calculateing last loop..." << endl;
202  ConstMuonRecHitContainer::const_iterator iter_less = --iter;
203  ++iter;
204  ConstMuonRecHitContainer::const_iterator iter_more = sortRecHits.begin();
205  cout << "more_Phi: " << (*iter_more)->globalPosition().phi() << ", less_Phi: " << (*iter_less)->globalPosition().phi() << ", iter_Phi: " << (*iter)->globalPosition().phi() << endl;
206  deltaPhi_less = (2 * M_PI) - ((*iter)->globalPosition().phi().value() - (*iter_less)->globalPosition().phi().value());
207  deltaPhi_more = (*iter)->globalPosition().phi().value() - (*iter_more)->globalPosition().phi().value();
208  }
209  else
210  {
211  cout << "Calculateing " << n << "st loop..." << endl;
212  ConstMuonRecHitContainer::const_iterator iter_less = --iter;
213  ++iter;
214  ConstMuonRecHitContainer::const_iterator iter_more = ++iter;
215  --iter;
216  cout << "more_Phi: " << (*iter_more)->globalPosition().phi() << ", less_Phi: " << (*iter_less)->globalPosition().phi() << ", iter_Phi: " << (*iter)->globalPosition().phi() << endl;
217  deltaPhi_less = (2 * M_PI) - ((*iter)->globalPosition().phi().value() - (*iter_less)->globalPosition().phi().value());
218  deltaPhi_more = (2 * M_PI) - ((*iter_more)->globalPosition().phi().value() - (*iter)->globalPosition().phi().value());
219  }
220  if(deltaPhi > deltaPhi_more)
221  deltaPhi = deltaPhi_more;
222  if(deltaPhi > deltaPhi_less)
223  deltaPhi = deltaPhi_less;
224 
225  cout << "For this loop deltaPhi_more is " << deltaPhi_more << endl;
226  cout << "For this loop deltaPhi_less is " << deltaPhi_less << endl;
227  cout << "For this loop deltaPhi is " << deltaPhi << endl;
228  }
229  return deltaPhi;
230  }
231 }
232 
234 
235  if(therecHits.size() >= 3)
236  {
237  theSeed->setrecHits(therecHits);
238  theSeed->seed();
239  }
240  else
241  cout << "Layer less than 3, could not fill a RPCSeedFinder" << endl;
242 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void configure(const edm::ParameterSet &iConfig)
bool lessPhi(const MuonTransientTrackingRecHit::ConstMuonRecHitPointer &it1, const MuonTransientTrackingRecHit::ConstMuonRecHitPointer &it2)
MuonTransientTrackingRecHit::ConstMuonRecHitContainer ConstMuonRecHitContainer
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
void setInput(MuonRecHitContainer(&recHits)[RPCLayerNumber])
#define RPCLayerNumber
int clusterSize() const
Definition: RPCRecHit.h:111
void complete(unsigned int LayerIndex)
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
T z() const
Definition: PV3DBase.h:63
int k[5][pyjets_maxn]
virtual TrackingRecHit * clone() const =0
void setOutput(RPCSeedFinder *Seed)
#define M_PI
Definition: BFit3D.cc:3
#define begin
Definition: vmac.h:31
int BunchX() const
Definition: RPCRecHit.h:103
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:61
void setLayers(const std::vector< unsigned int > &Layers)