1616#include <TCanvas.h>
1717#include <TFile.h>
1818#include <TH2F.h>
19- #include <TH1F.h>
2019#include <TNtuple.h>
2120#include <TString.h>
2221#include <TTree.h>
2322#include <TLine.h>
2423#include <TStyle.h>
2524
26- #include <set>
27-
28- #include "IOTOFBase/Segmentation.h"
25+ #include "IOTOFSimulation/Segmentation.h"
2926#include "IOTOFBase/IOTOFBaseParam.h"
3027#include "IOTOFBase/GeometryTGeo.h"
31- #include "IOTOFSimulation/Digitizer.h"
3228#include "DataFormatsIOTOF/Digit.h"
3329#include "ITSMFTSimulation/Hit.h"
3430#include "MathUtils/Utils.h"
3531#include "SimulationDataFormat/ConstMCTruthContainer.h"
3632#include "SimulationDataFormat/IOMCTruthContainerView.h"
3733#include "SimulationDataFormat/MCCompLabel.h"
38- #include "SimulationDataFormat/MCTrack.h"
39- #include "SimulationDataFormat/TrackReference.h"
4034#include "DetectorsBase/GeometryManager.h"
4135#include "CCDB/BasicCCDBManager.h"
4236
@@ -130,48 +124,15 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
130124
131125 digTree -> GetEntry (0 );
132126
133- // MC tracks
134- TFile * kineFile = TFile ::Open (kinefile .data ());
135- TTree * kineTree = (TTree * )kineFile -> Get ("o2sim" );
136- std ::vector < std ::vector < o2 ::MCTrack > * > mcTracksPerEvent (nevH , nullptr );
137- std ::vector < std ::vector < o2 ::TrackReference > * > mcTracksRefsPerEvent (nevH , nullptr );
138- kineTree -> SetBranchAddress ("MCTrack" , & mcTracksPerEvent [0 ]);
139- kineTree -> SetBranchAddress ("TrackRefs" , & mcTracksRefsPerEvent [0 ]);
140-
141- TH1F * hGenHitsEta [2 ][2 ] = {{
142- new TH1F ("hGenHitsEtaPrmL0" , "hGenHitsEtaPrmL0" , 40 , -2 , 2 ),
143- new TH1F ("hGenHitsEtaSecL0" , "hGenHitsEtaSecL0" , 40 , -2 , 2 ),
144- }, {
145- new TH1F ("hGenHitsEtaPrmL1" , "hGenHitsEtaPrmL1" , 40 , -2 , 2 ),
146- new TH1F ("hGenHitsEtaSecL1" , "hGenHitsEtaSecL1" , 40 , -2 , 2 ),
147- }};
148-
149127 // Load all MC hit events upfront and build the hit lookup map.
150128 for (int im = 0 ; im < nevH ; ++ im ) {
151129 hitTree -> SetBranchAddress ("TF3Hit" , & hitArray [im ]);
152130 hitTree -> GetEntry (im );
153- kineTree -> SetBranchAddress ("MCTrack" , & mcTracksPerEvent [im ]);
154- kineTree -> SetBranchAddress ("TrackRefs" , & mcTracksRefsPerEvent [im ]);
155- kineTree -> GetEntry (im );
156131 auto& mc2hit = mc2hitVec [im ];
157132 for (int ih = hitArray [im ]-> size (); ih -- ;) {
158133 const auto& hit = (* hitArray [im ])[ih ];
159134 uint64_t key = (uint64_t (hit .GetTrackID ()) << 32 ) + hit .GetDetectorID ();
160135 mc2hit .emplace (key , ih );
161-
162- auto & mcTrack = mcTracksPerEvent [im ]-> at (hit .GetTrackID ());
163- bool isPrimary = mcTrack .isPrimary ();
164-
165- int layer = gman -> getIOTOFLayer (hit .GetDetectorID ());
166- if (layer == 0 && isPrimary ) {
167- hGenHitsEta [0 ][0 ]-> Fill (mcTrack .GetEta ());
168- } else if (layer == 0 && !isPrimary ) {
169- hGenHitsEta [0 ][1 ]-> Fill (mcTrack .GetEta ());
170- } else if (layer == 1 && isPrimary ) {
171- hGenHitsEta [1 ][0 ]-> Fill (mcTrack .GetEta ());
172- } else if (layer == 1 && !isPrimary ) {
173- hGenHitsEta [1 ][1 ]-> Fill (mcTrack .GetEta ());
174- }
175136 }
176137 }
177138
@@ -182,21 +143,11 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
182143 plabelsArr -> copyandflatten (labels );
183144
184145 // LOOP on : ROFRecord array
185- TH1F * hRecoDigitEta [2 ][2 ] = {{
186- new TH1F ("hRecoDigitEtaPrmL0" , "hRecoDigitEtaPrmL0" , 40 , -2 , 2 ),
187- new TH1F ("hRecoDigitEtaSecL0" , "hRecoDigitEtaSecL0" , 40 , -2 , 2 ),
188- }, {
189- new TH1F ("hRecoDigitEtaPrmL1" , "hRecoDigitEtaPrmL1" , 40 , -2 , 2 ),
190- new TH1F ("hRecoDigitEtaSecL1" , "hRecoDigitEtaSecL1" , 40 , -2 , 2 ),
191- }};
192-
193- std ::unordered_map < uint64_t , std ::vector < int >> hitDigitMap ;
194146 for (unsigned int iROF = 0 ; iROF < rofArr .size (); ++ iROF ) {
195147
196148 const unsigned int rofIndex = rofArr [iROF ].getFirstEntry ();
197149 const unsigned int rofNEntries = rofArr [iROF ].getNEntries ();
198150
199- std ::unordered_map < int , std ::set < uint64_t >> tracksWithDigits ;
200151 // LOOP on : digits array
201152 for (unsigned int iDigit = rofIndex ; iDigit < rofIndex + rofNEntries ; iDigit ++ ) {
202153 if (iDigit % 1000 == 0 ) {
@@ -226,11 +177,10 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
226177 }
227178
228179 int trID = lab .getTrackID ();
229- int evtID = lab .getEventID ();
230180
231181 const auto gloD = gman -> getMatrixL2G (chipID )(locD ); // convert to global
232182
233- std ::unordered_map < uint64_t , int > * mc2hit = & mc2hitVec [evtID ];
183+ std ::unordered_map < uint64_t , int > * mc2hit = & mc2hitVec [lab . getEventID () ];
234184
235185 // get MC info
236186 uint64_t key = (uint64_t (trID ) << 32 ) + chipID ;
@@ -242,7 +192,7 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
242192 }
243193
244194 ////// HITS
245- Hit & hit = (* hitArray [evtID ])[hitEntry -> second ];
195+ Hit & hit = (* hitArray [lab . getEventID () ])[hitEntry -> second ];
246196
247197 auto xyzLocE = gman -> getMatrixL2G (chipID ) ^ (hit .GetPos ()); // inverse conversion from global to local
248198 auto xyzLocS = gman -> getMatrixL2G (chipID ) ^ (hit .GetPosStart ());
@@ -271,21 +221,6 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
271221 locH .X () - locD .X (), locH .Z () - locD .Z ()); /// difference in x and z between the hit and the digit in the local frame
272222 nt2 -> Fill (chipID , gloD .Z (), locHS .X () - locHE .X (), locHS .Z () - locHE .Z ()); /// differences between local hit start and hit end positions
273223
274- // Check if key is already in the set of tracks with digits,
275- // else we double count digits in efficiency calculation
276- // when using stepping
277- if (tracksWithDigits [evtID ].find (key ) == tracksWithDigits [evtID ].end ()) {
278- tracksWithDigits [evtID ].insert (key );
279- int digitLayer = gman -> getIOTOFLayer (chipID );
280- auto& mcTrack = mcTracksPerEvent [evtID ]-> at (trID );
281- bool isPrimary = mcTrack .isPrimary ();
282- hRecoDigitEta [digitLayer ][isPrimary ? 0 : 1 ]-> Fill (mcTrack .GetEta ());
283- }
284-
285- // Fill the hitDigitMap for later analysis
286- // Hit key from event ID and hit index
287- uint64_t hitKey = (uint64_t (evtID ) << 32 ) + hitEntry -> second ;
288- hitDigitMap [hitKey ].push_back (iDigit );
289224 } // end loop on digits array
290225
291226 } // end loop on ROFRecords
@@ -316,7 +251,7 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
316251 auto canvdXdZ = new TCanvas ("canvdXdZ" , "" , 1600 , 800 );
317252 canvdXdZ -> Divide (2 , 1 );
318253 canvdXdZ -> cd (1 );
319- nt -> Draw ("dx:dz>>h_dx_vs_dz_ITOF(1000 , -0.05 , 0.05, 1000 , -0.05 , 0.05 )" , "id >= 0 && id < 1920" , "colz" );
254+ nt -> Draw ("dx:dz>>h_dx_vs_dz_ITOF(600 , -0.03 , 0.03, 600 , -0.03 , 0.03 )" , "id >= 0 && id < 1920" , "colz" );
320255 addTLines (0.01 );
321256 auto h = (TH2F * )gPad -> GetPrimitive ("h_dx_vs_dz_ITOF" );
322257 Info ("ITOF" , "RMS(dx)=%.1f mu" , h -> GetRMS (2 ) * 1e4 );
@@ -349,72 +284,5 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
349284 canvdXdZHit -> SaveAs ("trkdigits_dxH_vs_dzH.pdf" );
350285
351286 f -> Write ();
352-
353- std ::string trackName [2 ] = {"Prm" , "Sec" };
354- f -> mkdir ("PrmTrkLayer0" );
355- f -> mkdir ("SecTrkLayer0" );
356- f -> mkdir ("PrmTrkLayer1" );
357- f -> mkdir ("SecTrkLayer1" );
358- for (int layer = 0 ; layer < 2 ; ++ layer ) {
359- for (int type = 0 ; type < 2 ; ++ type ) {
360- f -> cd (Form ("%sTrkLayer%d" , trackName [type ].c_str (), layer ));
361- hGenHitsEta [layer ][type ]-> Write ();
362- hRecoDigitEta [layer ][type ]-> Write ();
363- TH1F * hEffDigitEta = static_cast < TH1F * > (hRecoDigitEta [layer ][type ]-> Clone ("hEffDigitEta" ));
364- hEffDigitEta -> Divide (hGenHitsEta [layer ][type ]);
365- // Set errors
366- for (int bin = 1 ; bin <= hEffDigitEta -> GetNbinsX (); ++ bin ) {
367- double eff = hEffDigitEta -> GetBinContent (bin );
368- double nGen = hGenHitsEta [layer ][type ]-> GetBinContent (bin );
369- double err = 0.0 ;
370- if (nGen > 0 ) {
371- err = std ::sqrt (eff * (1 - eff ) / nGen );
372- }
373- hEffDigitEta -> SetBinError (bin , err );
374- }
375- hEffDigitEta -> SetTitle (";#eta;Digit Efficiency" );
376- hEffDigitEta -> Write ();
377- delete hEffDigitEta ;
378- }
379- }
380-
381- // Plot avg fraction of charge collected by digits for
382- // each hit vs eta, should reflect the digit efficiency
383- for (int layer = 0 ; layer < 2 ; ++ layer ) {
384- for (int type = 0 ; type < 2 ; ++ type ) {
385-
386- f -> cd (Form ("%sTrkLayer%d" , trackName [type ].c_str (), layer ));
387- TH2F * hFracCharge = new TH2F (Form ("hFracCharge_Layer%d_Type%d" , layer , type ), ";Fraction of charge collected by digits;Entries" , 40 , -2 , 2 , 200 , 0 , 1 );
388-
389- for (const auto& hitDigitPair : hitDigitMap ) {
390-
391- uint64_t hitKey = hitDigitPair .first ;
392- int evtID = static_cast < int > (hitKey >> 32 );
393- int hitIndex = static_cast < int > (hitKey & 0xFFFFFFFF );
394- const auto& hit = (* hitArray [evtID ])[hitIndex ];
395-
396- int hitLayer = gman -> getIOTOFLayer (hit .GetDetectorID ());
397- if (hitLayer != layer ) continue ;
398-
399- float energyLoss = hit .GetEnergyLoss (); // in GeV
400- int charge = static_cast < int > (energyLoss * 2.77778e+08 );
401-
402- auto& mcTrack = mcTracksPerEvent [evtID ]-> at (hit .GetTrackID ());
403- bool isPrimary = mcTrack .isPrimary ();
404- if ((isPrimary ? 0 : 1 ) != type ) continue ;
405-
406- const auto& digitIndices = hitDigitPair .second ;
407- float totalDigitCharge = 0.0f ;
408- for (int digitIndex : digitIndices ) {
409- totalDigitCharge += (* digArr )[digitIndex ].getCharge ();
410- }
411- float fracCharge = totalDigitCharge / charge ;
412- hFracCharge -> Fill (mcTrack .GetEta (), fracCharge );
413- }
414- hFracCharge -> Write ();
415- delete hFracCharge ;
416- }
417- }
418-
419287 f -> Close ();
420288}
0 commit comments