1515#include <TTree.h>
1616#include <cmath>
1717#include <vector>
18+ #include <iostream>
1819#include "CommonDataFormat/InteractionRecord.h"
1920#include "CommonDataFormat/IRFrame.h"
2021
2122using o2 ::InteractionRecord ;
2223using o2 ::dataformats ::IRFrame ;
2324
25+ const ULong64_t trigger0Bit = 54 ;
26+ const ULong64_t trigger1Bit = 2 ;
27+ const int bcDiffTolerance = 0 ;
28+
29+ struct bcTuple {
30+ bcTuple (ULong64_t bcAO2D , ULong64_t bcEvSel ) : bcAO2D (bcAO2D ), bcEvSel (bcEvSel ) {}
31+ ULong64_t bcAO2D {0ull };
32+ ULong64_t bcEvSel {0ull };
33+ bool operator == (const bcTuple & t ) const
34+ {
35+ return (this -> bcAO2D == t .bcAO2D && this -> bcEvSel == t .bcEvSel );
36+ }
37+ };
38+
2439struct selectedFrames : public IRFrame {
25- selectedFrames (ULong64_t triMask [2 ], ULong64_t selMask [2 ], const IRFrame & frame ) : IRFrame (frame ), triMask {triMask [0 ], triMask [1 ]}, selMask {selMask [0 ], selMask [1 ]} {}
26- ULong64_t triMask [2 ]{0ull }, selMask [2 ]{0ull };
40+ selectedFrames (ULong64_t bcAO2D , ULong64_t bcEvSel , ULong64_t triMask [2 ], ULong64_t selMask [2 ], const IRFrame & frame ) : IRFrame (frame ), bcAO2D ( bcAO2D ), bcEvSel ( bcEvSel ), triMask {triMask [0 ], triMask [1 ]}, selMask {selMask [0 ], selMask [1 ]} {}
41+ ULong64_t triMask [2 ]{0ull }, selMask [2 ]{0ull }, bcAO2D , bcEvSel ;
2742};
2843
2944std ::vector < selectedFrames > getSelectedFrames (TFile & file )
@@ -56,42 +71,199 @@ std::vector<selectedFrames> getSelectedFrames(TFile& file)
5671 if (!selMask [0 ] && !selMask [1 ]) {
5772 continue ;
5873 }
59- InteractionRecord irstart , irend ;
60- irstart .setFromLong (std ::min (bcAO2D , bcEvSel ));
61- irend .setFromLong (std ::max (bcAO2D , bcEvSel ));
62- IRFrame frame (irstart , irend );
63- selectedFrames .push_back ({triMask , selMask , frame });
74+ if (selMask [0 ] & BIT (trigger0Bit ) || selMask [1 ] & BIT (trigger1Bit )) {
75+ InteractionRecord irstart , irend ;
76+ irstart .setFromLong (std ::min (bcAO2D , bcEvSel ));
77+ irend .setFromLong (std ::max (bcAO2D , bcEvSel ));
78+ IRFrame frame (irstart , irend );
79+ selectedFrames .push_back ({bcAO2D , bcEvSel , triMask , selMask , frame });
80+ }
6481 }
82+ std ::cout << "TreeSize: " << tree -> GetEntries () << std ::endl ;
6583 }
84+ std ::cout << "Size: " << selectedFrames .size () << std ::endl ;
6685 return selectedFrames ;
6786}
6887
6988void checkBCrangesSkimming (std ::string originalFileName = "bcRanges_fullrun.root" , std ::string skimmedFileName = "bcRanges_fullrun_skimmed.root" )
7089{
7190 TFile originalFile (originalFileName .c_str (), "READ" );
7291 TFile skimmedFile (skimmedFileName .c_str (), "READ ");
92+ TH1F * hTriggerCounter = new TH1F ("hTriggerCounter" , "hTriggerCounter" , 3 , 0.5 , 3.5 );
93+ hTriggerCounter -> GetXaxis ()-> SetBinLabel (1 , "Original" );
94+ hTriggerCounter -> GetXaxis ()-> SetBinLabel (2 , "Skimmed" );
95+ TH1F * hNumCounter = new TH1F ("hNumCounter" , "hTriggerCounter" , 10 , -0.5 , 9.5 );
96+ TH1F * hPairedTriggerCounter = new TH1F ("hPairedTriggerCounter" , "hPairedTriggerCounter" , 4 , 0.5 , 4.5 );
97+ hPairedTriggerCounter -> GetXaxis ()-> SetBinLabel (1 , "Total" );
98+ hPairedTriggerCounter -> GetXaxis ()-> SetBinLabel (2 , "Same AO2D BC" );
99+ hPairedTriggerCounter -> GetXaxis ()-> SetBinLabel (3 , "Same EvSel BC" );
100+ hPairedTriggerCounter -> GetXaxis ()-> SetBinLabel (4 , "Same Both BC" );
101+ TH1F * hSinglePairCheck = new TH1F ("hSinglePairCheck" , "hSinglePairCheck" , 4 , 0.5 , 4.5 );
102+ hSinglePairCheck -> GetXaxis ()-> SetBinLabel (1 , "Total" );
103+ hSinglePairCheck -> GetXaxis ()-> SetBinLabel (2 , "Same AO2D BC" );
104+ hSinglePairCheck -> GetXaxis ()-> SetBinLabel (3 , "Same EvSel BC" );
105+ hSinglePairCheck -> GetXaxis ()-> SetBinLabel (4 , "Same Both BC" );
106+ TH1F * hMultiPairCheck = new TH1F ("hMultiPairCheck" , "hMultiPairCheck" , 5 , 0.5 , 5.5 );
107+ hMultiPairCheck -> GetXaxis ()-> SetBinLabel (1 , "Total" );
108+ hMultiPairCheck -> GetXaxis ()-> SetBinLabel (2 , "Total Pair" );
109+ hMultiPairCheck -> GetXaxis ()-> SetBinLabel (3 , "Same AO2D BC" );
110+ hMultiPairCheck -> GetXaxis ()-> SetBinLabel (4 , "Same EvSel BC" );
111+ hMultiPairCheck -> GetXaxis ()-> SetBinLabel (5 , "Same Both BC" );
112+ TH1F * hBCDiffAO2D = new TH1F ("hBCDiffAO2D" , "hBCDiffAO2D" , 1000 , -5.e3 , 5.e3 );
113+ TH1F * hBCDiffEvSel = new TH1F ("hBCDiffEvSel" , "hBCDiffEvSel" , 1000 , -5.e3 , 5.e3 );
73114
115+ TH1F * hBCOriginal = new TH1F ("hBCOriginal" , "hBCOriginal" , 4 , 0.5 , 4.5 );
116+ hBCOriginal -> GetXaxis ()-> SetBinLabel (1 , "Total" );
117+ hBCOriginal -> GetXaxis ()-> SetBinLabel (2 , "Same AO2D BC" );
118+ hBCOriginal -> GetXaxis ()-> SetBinLabel (3 , "Same EvSel BC" );
119+ hBCOriginal -> GetXaxis ()-> SetBinLabel (4 , "Same Both BC" );
120+ TH1F * hBCSkimmed = new TH1F ("hBCSkimmed" , "hBCSkimmed" , 4 , 0.5 , 4.5 );
121+ hBCSkimmed -> GetXaxis ()-> SetBinLabel (1 , "Total" );
122+ hBCSkimmed -> GetXaxis ()-> SetBinLabel (2 , "Same AO2D BC" );
123+ hBCSkimmed -> GetXaxis ()-> SetBinLabel (3 , "Same EvSel BC" );
124+ hBCSkimmed -> GetXaxis ()-> SetBinLabel (4 , "Same Both BC" );
125+
126+ auto t1 = std ::chrono ::steady_clock ::now ();
74127 auto originalFrames = getSelectedFrames (originalFile );
75128 auto skimmedFrames = getSelectedFrames (skimmedFile );
129+ auto t2 = std ::chrono ::steady_clock ::now ();
130+ int d1 = std ::chrono ::duration_cast < std ::chrono ::milliseconds > (t2 - t1 ).count ();
131+ std ::cout << "Readin Time: " << d1 << std ::endl ;
76132
133+ auto t3 = std ::chrono ::steady_clock ::now ();
77134 std ::sort (originalFrames .begin (), originalFrames .end (), [](const selectedFrames & a , const selectedFrames & b ) {
78135 return a .getMin () < b .getMin ();
79136 });
80137 std ::sort (skimmedFrames .begin (), skimmedFrames .end (), [](const selectedFrames & a , const selectedFrames & b ) {
81138 return a .getMin () < b .getMin ();
82139 });
140+ auto t4 = std ::chrono ::steady_clock ::now ();
141+ int d2 = std ::chrono ::duration_cast < std ::chrono ::milliseconds > (t4 - t3 ).count ();
142+ std ::cout << "Sort Time: " << d2 << std ::endl ;
83143
144+ auto t5 = std ::chrono ::steady_clock ::now ();
145+ std ::vector < bcTuple > bcSet ;
146+ std ::vector < ULong64_t > bcAO2DSet ;
147+ std ::vector < ULong64_t > bcEvSelSet ;
84148 for (auto frame : originalFrames ) {
85- bool found = false;
86- frame .getMin () -= 1000 ;
87- frame .getMax () += 1000 ;
88- for (auto & skimmedFrame : skimmedFrames ) {
89- if (skimmedFrame .getMin () > frame .getMax ()) {
90- break ;
149+ if (frame .selMask [0 ] & BIT (trigger0Bit )) {
150+ bool found = false;
151+ hTriggerCounter -> Fill (1 );
152+ hBCOriginal -> Fill (1 );
153+ auto p1 = std ::find_if (bcSet .begin (), bcSet .end (), [& ](const auto& val ) { return val .bcAO2D == frame .bcAO2D ; });
154+ if (p1 != bcSet .end ()) {
155+ hBCOriginal -> Fill (2 );
156+ }
157+ auto p2 = std ::find_if (bcSet .begin (), bcSet .end (), [& ](const auto& val ) { return val .bcEvSel == frame .bcEvSel ; });
158+ if (p2 != bcSet .end ()) {
159+ hBCOriginal -> Fill (3 );
160+ }
161+ bcTuple currentBC (frame .bcAO2D , frame .bcEvSel );
162+ auto p3 = std ::find (bcSet .begin (), bcSet .end (), currentBC );
163+ if (p3 == bcSet .end ()) {
164+ bcSet .push_back (currentBC );
165+ } else {
166+ hBCOriginal -> Fill (4 );
167+ }
168+ // std::cout << "------------------------------------------------" << std::endl;
169+ frame .getMin () -= bcDiffTolerance ;
170+ frame .getMax () += bcDiffTolerance ;
171+ std ::vector < bcTuple > skimmedbcs ;
172+ int n = 0 ;
173+ for (auto& skimmedFrame : skimmedFrames ) {
174+ if (skimmedFrame .getMin () > frame .getMax ()) {
175+ break ;
176+ }
177+ if (!frame .isOutside (skimmedFrame )) {
178+ found = frame .selMask [0 ] & skimmedFrame .selMask [0 ] || frame .selMask [1 ] & skimmedFrame .selMask [1 ];
179+ found = found && (frame .bcAO2D == skimmedFrame .bcAO2D || frame .bcEvSel == skimmedFrame .bcEvSel );
180+ if (found ) {
181+ hPairedTriggerCounter -> Fill (1 );
182+ if (frame .bcAO2D == skimmedFrame .bcAO2D ) {
183+ hPairedTriggerCounter -> Fill (2 );
184+ }
185+ if (frame .bcEvSel == skimmedFrame .bcEvSel ) {
186+ hPairedTriggerCounter -> Fill (3 );
187+ if (frame .bcAO2D == skimmedFrame .bcAO2D ) {
188+ hPairedTriggerCounter -> Fill (4 );
189+ }
190+ }
191+ skimmedbcs .push_back ({skimmedFrame .bcAO2D , skimmedFrame .bcEvSel });
192+ n ++ ;
193+ }
194+ }
91195 }
92- if (!frame .isOutside (skimmedFrame )) {
93- found = frame .selMask [0 ] & skimmedFrame .selMask [0 ] || frame .selMask [1 ] & skimmedFrame .selMask [1 ];
196+ if (n == 0 ) {
197+ // std::cout << "Trigger not found!!! " << n << std::endl;
198+ } else if (n == 1 ) {
199+ hSinglePairCheck -> Fill (1 );
200+ hBCDiffAO2D -> Fill (frame .bcAO2D - skimmedbcs [0 ].bcAO2D );
201+ hBCDiffEvSel -> Fill (frame .bcEvSel - skimmedbcs [0 ].bcEvSel );
202+ if (frame .bcAO2D == skimmedbcs [0 ].bcAO2D ) {
203+ hSinglePairCheck -> Fill (2 );
204+ }
205+ if (frame .bcEvSel == skimmedbcs [0 ].bcEvSel ) {
206+ hSinglePairCheck -> Fill (3 );
207+ if (frame .bcAO2D == skimmedbcs [0 ].bcAO2D ) {
208+ hSinglePairCheck -> Fill (4 );
209+ }
210+ }
211+ } else {
212+ // std::cout << "Unexpected trigger!!! " << n << std::endl;
213+ hMultiPairCheck -> Fill (1 );
214+ for (auto skimmedbc : skimmedbcs ) {
215+ hMultiPairCheck -> Fill (2 );
216+ if (frame .bcAO2D == skimmedbc .bcAO2D ) {
217+ hMultiPairCheck -> Fill (3 );
218+ }
219+ if (frame .bcEvSel == skimmedbc .bcEvSel ) {
220+ hMultiPairCheck -> Fill (4 );
221+ if (frame .bcAO2D == skimmedbc .bcAO2D ) {
222+ hMultiPairCheck -> Fill (5 );
223+ }
224+ }
225+ }
94226 }
227+ hNumCounter -> Fill (n );
95228 }
96229 }
97- }
230+ auto t6 = std ::chrono ::steady_clock ::now ();
231+ int d3 = std ::chrono ::duration_cast < std ::chrono ::milliseconds > (t6 - t5 ).count ();
232+ std ::cout << "Search Time: " << d3 << std ::endl ;
233+
234+ bcSet .clear ();
235+ for (auto & skimmedFrame : skimmedFrames ) {
236+ if (skimmedFrame .selMask [0 ] & BIT (trigger0Bit ) || skimmedFrame .selMask [1 ] & (trigger1Bit )) {
237+ hTriggerCounter -> Fill (2 );
238+ hBCSkimmed -> Fill (1 );
239+ auto p1 = std ::find_if (bcSet .begin (), bcSet .end (), [& ](const auto& val ) { return val .bcAO2D == skimmedFrame .bcAO2D ; });
240+ if (p1 != bcSet .end ()) {
241+ hBCSkimmed -> Fill (2 );
242+ }
243+ auto p2 = std ::find_if (bcSet .begin (), bcSet .end (), [& ](const auto& val ) { return val .bcEvSel == skimmedFrame .bcEvSel ; });
244+ if (p2 != bcSet .end ()) {
245+ hBCSkimmed -> Fill (3 );
246+ }
247+ bcTuple currentBC (skimmedFrame .bcAO2D , skimmedFrame .bcEvSel );
248+ auto p3 = std ::find (bcSet .begin (), bcSet .end (), currentBC );
249+ if (p3 == bcSet .end ()) {
250+ bcSet .push_back (currentBC );
251+ } else {
252+ hBCSkimmed -> Fill (4 );
253+ }
254+ }
255+ }
256+
257+ TFile fout ("check.root" , "RECREATE" );
258+ fout .cd ();
259+ hTriggerCounter -> Write ();
260+ hBCOriginal -> Write ();
261+ hBCSkimmed -> Write ();
262+ hNumCounter -> Write ();
263+ hPairedTriggerCounter -> Write ();
264+ hSinglePairCheck -> Write ();
265+ hBCDiffAO2D -> Write ();
266+ hBCDiffEvSel -> Write ();
267+ hMultiPairCheck -> Write ();
268+ fout .Close ();
269+ }
0 commit comments