@@ -50,16 +50,7 @@ MPThetaMatching::~MPThetaMatching() { finish(); }
5050// ============================================================================
5151// Main methods (initialise, run, finish)
5252// ============================================================================
53- void MPThetaMatching::initialise (const edm::EventSetup &iEventSetup) {
54- totINphi = 0 ;
55- totOUTphi = 0 ;
56- totINtheta = 0 ;
57- totOUTtheta = 0 ;
58- st4OUTphi = 0 ;
59- hqOUTphi = 0 ;
60- nothetaOUTphi = 0 ;
61- nophiOUTtheta = 0 ;
62- }
53+ void MPThetaMatching::initialise (const edm::EventSetup &iEventSetup) {}
6354
6455void MPThetaMatching::run (edm::Event &iEvent,
6556 const edm::EventSetup &iEventSetup,
@@ -76,8 +67,6 @@ void MPThetaMatching::run(edm::Event &iEvent,
7667 else if (scenario_ == SLICE_TEST)
7768 shift_back = 400 ;
7869
79- // cout<<"############NEW EVENT####"<< "inMPaths: "<<inMPaths.size()<<endl;
80-
8170 if (th_option_ > 0 ) {
8271 auto filteredMPs = filter (inMPaths, shift_back);
8372 for (auto &mp : filteredMPs)
@@ -88,23 +77,9 @@ void MPThetaMatching::run(edm::Event &iEvent,
8877 << " MPThetaMatching: th_option can NOT be negative!!! Check settings. Saving all MPs for the moment" << endl;
8978 outMPaths = inMPaths; // no filter at all
9079 }
91-
92- // if(doLog) cout << "Before filter #TPs:" << inMPaths.size() << " after: " << outMPaths.size() << endl;
9380}
9481
95- void MPThetaMatching::finish () {
96- totOUTphi = totOUTphi - st4OUTphi - nothetaOUTphi - nophiOUTtheta;
97- totINphi = totINphi - nothetaOUTphi - nophiOUTtheta;
98- std::cout << " Rejected rate Phi: " << 1 - float (totOUTphi) / totINphi << endl;
99- std::cout << " Rejected rate Theta: " << 1 - float (totOUTtheta) / totINtheta << endl;
100- std::cout << " Rejected rate total: " << 1 - float (totOUTphi + totOUTtheta) / (totINtheta + totINphi) << endl;
101-
102- totOUTphi = totOUTphi - hqOUTphi;
103- totINphi = totINphi - hqOUTphi;
104- std::cout << " Rejected rate Phi (excluding HQ): " << 1 - float (totOUTphi) / totINphi << endl;
105- std::cout << " Rejected rate total (excluding HQ): " << 1 - float (totOUTphi + totOUTtheta) / (totINtheta + totINphi)
106- << endl;
107- };
82+ void MPThetaMatching::finish (){};
10883
10984// /////////////////////////
11085// / OTHER METHODS
@@ -122,34 +97,20 @@ std::vector<metaPrimitive> MPThetaMatching::filter(std::vector<metaPrimitive> in
12297 if (slId.superLayer () == 2 )
12398 thetaMPs.push_back (mp);
12499 else if (chId.station () == 4 ) // No theta matching for MB4, save MP
125- {
126100 outMPs.push_back (mp);
127- st4OUTphi += 1 ;
128- } else if (mp.quality > th_quality_) // don't do theta matching for q > X, save
101+ else if (mp.quality > th_quality_) // don't do theta matching for q > X, save
129102 {
130103 outMPs.push_back (mp);
131104 phiMPs.push_back (mp); // keep them in the loop to filter in Theta for cases where there are no other phiMPs
132- hqOUTphi += 1 ;
133105 } else
134106 phiMPs.push_back (mp);
135107 }
136108
137- bool doLog = false ;
138- if (thetaMPs.size () > 0 || phiMPs.size () > 0 ) {
139- cout << " Initial #TPs Theta: " << thetaMPs.size () << " Phi: " << phiMPs.size () << endl;
140- doLog = true ;
141- }
142-
143- totINphi += phiMPs.size ();
144- totINtheta += thetaMPs.size ();
145-
146109 // Order Theta MPs by quality
147110 std::sort (thetaMPs.begin (), thetaMPs.end (), compareMPs);
148111
149112 // Use only best quality theta MP in chamber
150- // thetaMPs = getBestThetaMPInChamber(thetaMPs);
151- if (doLog)
152- cout << " Intermediate #TPs Theta: " << thetaMPs.size () << endl;
113+ thetaMPs = getBestThetaMPInChamber (thetaMPs);
153114
154115 // Loop on phi, save those at chamber without Theta MPs
155116 for (auto &mp : phiMPs) {
@@ -161,17 +122,15 @@ std::vector<metaPrimitive> MPThetaMatching::filter(std::vector<metaPrimitive> in
161122 int station = chId.station ();
162123
163124 if (!isThereThetaMPInChamber (sector, wheel, station, thetaMPs)) {
164- if (mp.quality <= th_quality_) { // Has it been saved already?
165- outMPs.push_back (mp); // No theta MPs in chamber to match, save MP
166- nothetaOUTphi += 1 ;
167- }
125+ if (mp.quality <= th_quality_) // Has it been saved already?
126+ outMPs.push_back (mp); // No theta MPs in chamber to match, save MP
168127 }
169128 }
170129
171130 // Loop on theta (already ordered)
172131 int oldSector = 0 ;
173132 int oldStation = 0 ;
174- int oldWheel = 0 ;
133+ int oldWheel = - 999 ;
175134 // container to decide which theta-phi pair to save
176135 std::vector<std::tuple<metaPrimitive, metaPrimitive, float >>
177136 deltaTimePosPhiCands; // thetaMP, phiMP, difference in TimePosition
@@ -203,15 +162,10 @@ std::vector<metaPrimitive> MPThetaMatching::filter(std::vector<metaPrimitive> in
203162 // float t0 = (mpTheta.t0 - shift_back * LHC_CLK_FREQ) * ((float) TIME_TO_TDC_COUNTS / (float) LHC_CLK_FREQ);
204163 float t0 = ((int )round (mpTheta.t0 / (float )LHC_CLK_FREQ)) - shift_back;
205164 float posRefZ = zFE[wheel + 2 ];
206- if (doLog)
207- cout << " Theta wh se st q t0: " << wheel << " " << sector << " " << station << " " << mpTheta.quality << " "
208- << mpTheta.t0 << endl;
209165
210166 if (wheel == 0 && (sector == 1 || sector == 4 || sector == 5 || sector == 8 || sector == 9 || sector == 12 ))
211167 posRefZ = -posRefZ;
212168 float posZ = abs (mpTheta.phi );
213- // cout << "t0: " << t0 << endl;
214- // cout << "posZ: " << posZ << endl;
215169
216170 // Loop in Phis
217171 for (metaPrimitive &mpPhi : phiMPs) {
@@ -221,19 +175,13 @@ std::vector<metaPrimitive> MPThetaMatching::filter(std::vector<metaPrimitive> in
221175 int sector2 = chId2.sector ();
222176 int wheel2 = chId2.wheel ();
223177 int station2 = chId2.station ();
224- if (doLog)
225- cout << " Phi wheel: " << wheel2 << " sector " << sector2 << " station: " << station2 << " q: " << mpPhi.quality
226- << " t0: " << mpPhi.t0 << endl;
227178
228179 if (station2 != station || sector2 != sector || wheel2 != wheel)
229180 continue ;
230181
231- // float t02 = (mpPhi.t0 - shift_back * LHC_CLK_FREQ) * ((float) TIME_TO_TDC_COUNTS / (float) LHC_CLK_FREQ);
232182 float t02 = ((int )round (mpPhi.t0 / (float )LHC_CLK_FREQ)) - shift_back;
233183
234- // cout << "posRefZ: " << posRefZ << " Z: " << posZ / ZRES_CONV << endl;
235184 float tphi = t02 - abs (posZ / ZRES_CONV - posRefZ) / vwire;
236- // cout << "tphi: " << tphi << endl;
237185
238186 int LR = -1 ;
239187 if (wheel == 0 && (sector == 3 || sector == 4 || sector == 7 || sector == 8 || sector == 11 || sector == 12 ))
@@ -242,65 +190,22 @@ std::vector<metaPrimitive> MPThetaMatching::filter(std::vector<metaPrimitive> in
242190 LR = pow (-1 , wheel + sector + 1 );
243191 else if (wheel < 0 )
244192 LR = pow (-1 , -wheel + sector);
245- // cout << "wh st se: " << wheel << " " << station << " " << sector << " LR: " << LR << endl;
246193
247194 float posRefX = LR * xFE[station - 1 ];
248195 float ttheta = t0 - (mpPhi.x / 1000 - posRefX) / vwire;
249- // cout << "posRefX: " << posRefX << " X: " << mp2.x / 1000 << endl;
250- // cout << "ttheta: " << ttheta << endl;
251196
252197 deltaTimePosPhiCands.push_back ({mpTheta, mpPhi, abs (tphi - ttheta)});
253- // cout << "deltaTimePosPhiCands: " << deltaTimePosPhiCands.size() << endl;
254198 } // loop in phis
255199
256200 if (deltaTimePosPhiCands.size () == 0 ) {
257201 outMPs.push_back (mpTheta); // save ThetaMP when there is no phi TPs
258202 savedThetaMPs.push_back (mpTheta);
259- nophiOUTtheta += 1 ;
260203 }
261204 } // loop in thetas
262205
263206 if (deltaTimePosPhiCands.size () > 0 )
264207 orderAndSave (deltaTimePosPhiCands, &outMPs, &savedThetaMPs); // do once more for last theta TP in loop
265208
266- if (doLog)
267- cout << " After #TPs Theta: " << savedThetaMPs.size () << " Phi: " << outMPs.size () - savedThetaMPs.size () << endl;
268-
269- if (inMPs.size () > outMPs.size ())
270- cout << " ########### TP size reduced from: " << inMPs.size () << " to: " << outMPs.size ()
271- << " rate: " << float (outMPs.size ()) / inMPs.size () << endl;
272- else if (outMPs.size () > inMPs.size ())
273- cout << " $$$$$$$$$$$$$ TP size enlarged from: " << inMPs.size () << " to: " << outMPs.size () << endl;
274-
275- if (phiMPs.size () > (outMPs.size () - savedThetaMPs.size ()))
276- cout << " ########### TP Phi size reduced from: " << phiMPs.size ()
277- << " to: " << outMPs.size () - savedThetaMPs.size ()
278- << " rate: " << float ((outMPs.size () - savedThetaMPs.size ())) / phiMPs.size () << endl;
279-
280- if (thetaMPs.size () > savedThetaMPs.size ())
281- cout << " ########### TP Theta size reduced from: " << thetaMPs.size () << " to: " << savedThetaMPs.size ()
282- << " rate: " << float (savedThetaMPs.size ()) / thetaMPs.size () << endl;
283-
284- totOUTtheta = totOUTtheta + savedThetaMPs.size ();
285- totOUTphi = totOUTphi + (outMPs.size () - savedThetaMPs.size ());
286-
287- for (const auto &mp1 : outMPs) {
288- cout << " FINAL OUTPUT OF WHAT IT IS SAVED" << endl;
289- DTChamberId chId1 (mp1.rawId );
290- DTSuperLayerId slId1 (mp1.rawId );
291-
292- int sector1 = chId1.sector ();
293- int wheel1 = chId1.wheel ();
294- int station1 = chId1.station ();
295- if (slId1.superLayer () == 2 )
296- cout << " Theta wheel: " << wheel1 << " sector " << sector1 << " station1: " << station1 << " q: " << mp1.quality
297- << " t0: " << mp1.t0 << endl;
298- else
299- cout << " Phi wheel: " << wheel1 << " sector " << sector1 << " station1: " << station1 << " q: " << mp1.quality
300- << " t0: " << mp1.t0 << endl;
301- cout << endl;
302- }
303-
304209 return outMPs;
305210};
306211
@@ -329,46 +234,49 @@ std::vector<metaPrimitive> MPThetaMatching::getBestThetaMPInChamber(std::vector<
329234 // if there are more than 1 theta TPs in chamber, use and save only the one with highest quality
330235 int sector1 = chId1.sector ();
331236 int wheel1 = chId1.wheel ();
332- int station1 = chId1.station ();
333- cout << " Theta wheel: " << wheel1 << " sector " << sector1 << " station1: " << station1 << " q: " << mp1.quality
334- << " t0: " << mp1.t0 << endl;
335- // Theta TPs (SL2) can be only q=1 (3hits) or q=3 (4 hits)
336- if (mp1.quality > 1 ) {
337- bestThetaMPs.push_back (mp1);
338- continue ;
339- }
340-
341- int nTPs = 0 ;
342- bool saved = false ;
343- // if q=1
344- for (const auto &mp2 : thetaMPs) {
345- DTChamberId chId2 (mp2.rawId );
346- DTSuperLayerId slId2 (mp2.rawId );
347-
348- int sector2 = chId2.sector ();
349- int wheel2 = chId2.wheel ();
350- int station2 = chId2.station ();
237+ if (wheel1 == 0 ) { // Exception for Wheel 0 ONLY, to take into account background in other chambers
238+ int station1 = chId1.station ();
239+ // Theta TPs (SL2) can be only q=1 (3hits) or q=3 (4 hits)
240+ if (mp1.quality > 1 ) {
241+ bestThetaMPs.push_back (mp1);
242+ continue ;
243+ }
351244
352- if (sector1 == sector2 && wheel1 == wheel2 && station1 == station2) {
353- if (mp2.quality > mp1.quality && (abs (wheel1) != 2 || station1 > 2 )) { // exception for WH+-2 MB1/2
354- saved = true ;
355- break ; // there is a q=3 and it was already saved
356- } else if (mp2.quality == mp1.quality && mp2.t0 != mp1.t0 ) {
357- saved = true ;
358- bestThetaMPs.push_back (mp1);
359- break ; // if there are more than 1 with same q=1, save both
360- } else if (abs (wheel1) == 2 && station1 < 3 ) {
361- saved = true ;
362- bestThetaMPs.push_back (mp1);
363- break ;
245+ int nTPs = 0 ;
246+ bool saved = false ;
247+ // if q=1
248+ for (const auto &mp2 : thetaMPs) {
249+ DTChamberId chId2 (mp2.rawId );
250+ DTSuperLayerId slId2 (mp2.rawId );
251+
252+ int sector2 = chId2.sector ();
253+ int wheel2 = chId2.wheel ();
254+ int station2 = chId2.station ();
255+
256+ if (sector1 == sector2 && wheel1 == wheel2 && station1 == station2) {
257+ if (mp2.quality > mp1.quality && wheel1 == 0 ) {
258+ saved = true ;
259+ break ; // there is a q=3 and it was already saved
260+ } else if (mp2.quality == mp1.quality && mp2.t0 != mp1.t0 ) {
261+ saved = true ;
262+ bestThetaMPs.push_back (mp1);
263+ break ; // if there are more than 1 with same q=1, save both
264+ } else if (abs (wheel1) == 2 && station1 < 3 ) {
265+ saved = true ;
266+ bestThetaMPs.push_back (mp1);
267+ break ;
268+ }
269+
270+ nTPs++;
364271 }
365-
366- nTPs++;
367272 }
368- }
369- if (nTPs == 1 && !saved)
370- bestThetaMPs.push_back (mp1); // only one Theta TP in chamber and it is q=1
371- }
273+ if (nTPs == 1 && !saved)
274+ bestThetaMPs.push_back (mp1); // only one Theta TP in chamber and it is q=1
275+ } // wheel ==0
276+
277+ else
278+ bestThetaMPs.push_back (mp1);
279+ } // loop in thetaMPs
372280
373281 return bestThetaMPs;
374282};
@@ -380,34 +288,32 @@ void MPThetaMatching::orderAndSave(std::vector<std::tuple<metaPrimitive, metaPri
380288 std::sort (deltaTimePosPhiCands.begin (), deltaTimePosPhiCands.end (), comparePairs);
381289 int count = 0 ;
382290
383- for ( std::tuple<metaPrimitive, metaPrimitive, float > &p :
291+ for (std::tuple<metaPrimitive, metaPrimitive, float > &p :
384292 deltaTimePosPhiCands) { // save up to nth nearest Theta-Phi pair candidate
385- cout << " Count: " << count << " abs(tphi-ttheta): " << std::get<2 >(p) << " qTheta: " << std::get<0 >(p).quality
386- << " qPhi: " << std::get<1 >(p).quality << endl;
387293 if (std::get<1 >(p).quality > th_quality_)
388294 continue ;
389295 DTChamberId chId (std::get<1 >(p).rawId );
390296
391- // if ((abs(chId.wheel()) == 2 && chId.station() < 3 && count < th_option_ + 1) || //save an extra pair for WH+-2MB1/2
392- if ( count < th_option_) {
393- std::get<0 >(p).t0 = std::get<1 >(p).t0 ;
297+ if ((abs (chId.wheel ()) == 2 && chId.station () < 3 && count < th_option_ + 1 ) || // save an extra pair for WH+-2MB1/2
298+ count < th_option_) {
299+ std::get<0 >(p).t0 = std::get<1 >(p).t0 ; // replace t0 by associated phi t0
394300 outMPs->push_back (std::get<1 >(p)); // add PhiMP
395301 outMPs->push_back (std::get<0 >(p)); // add ThetaMP
396302 savedThetaMPs->push_back (std::get<0 >(p)); // for accounting
397303 count++;
398304 } else
399- break ; // FIXME: avoid Theta duplicates when saving more than one pair
305+ break ; // avoid Theta duplicates when saving more than one pair
400306 }
401307
402- for (std::tuple<metaPrimitive, metaPrimitive, float > &p : deltaTimePosPhiCands) {
308+ for (std::tuple<metaPrimitive, metaPrimitive, float > &p :
309+ deltaTimePosPhiCands) { // save theta TP when paired Phi was above th_quality_
403310 DTChamberId chId (std::get<1 >(p).rawId );
404- if (count < th_option_ ){ // || (abs(chId.wheel()) == 2 && chId.station() < 3 && count < (th_option_ + 1))) {
311+ if (count < th_option_ || (abs (chId.wheel ()) == 2 && chId.station () < 3 && count < (th_option_ + 1 ))) {
405312 if (std::get<1 >(p).quality > th_quality_) {
406- std::get<0 >(p).t0 = std::get<1 >(p).t0 ;
407- outMPs->push_back (std::get<0 >(p)); // add ThetaMP
313+ // if (abs(chId.wheel())!=0)
314+ std::get<0 >(p).t0 = std::get<1 >(p).t0 ; // replace t0 by associated phi t0
315+ outMPs->push_back (std::get<0 >(p)); // add ThetaMP
408316 savedThetaMPs->push_back (std::get<0 >(p));
409- cout << " Count: " << count << " abs(tphi-ttheta): " << std::get<2 >(p) << " qTheta: " << std::get<0 >(p).quality
410- << " qPhi: " << std::get<1 >(p).quality << " no Phis below qcut to match" << endl;
411317 count++;
412318 }
413319 } else
0 commit comments