4242#include " Steer/MCKinematicsReader.h"
4343#include " DCAFitter/DCAFitterN.h"
4444#include " MathUtils/fit.h"
45+ #include " GlobalTrackingStudy/V0Ext.h"
4546
4647namespace o2 ::svstudy
4748{
@@ -70,6 +71,7 @@ class SVStudySpec : public Task
7071 void endOfStream (EndOfStreamContext& ec) final ;
7172 void finaliseCCDB (ConcreteDataMatcher& matcher, void * obj) final ;
7273 void process (o2::globaltracking::RecoContainer& recoData);
74+ o2::dataformats::V0Ext processV0 (int iv, o2::globaltracking::RecoContainer& recoData);
7375
7476 private:
7577 void updateTimeDependentParams (ProcessingContext& pc);
@@ -78,7 +80,7 @@ class SVStudySpec : public Task
7880 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest ;
7981 bool mUseMC {false }; // /< MC flag
8082 std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut ;
81- bool mSelK0 = false ;
83+ float mSelK0 = - 1 ;
8284 bool mRefit = false ;
8385 float mMaxEta = 0.8 ;
8486 float mBz = 0 ;
@@ -92,7 +94,7 @@ void SVStudySpec::init(InitContext& ic)
9294 o2::base::GRPGeomHelper::instance ().setRequest (mGGCCDBRequest );
9395 mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(" svStudy.root" , " recreate" );
9496 mRefit = ic.options ().get <bool >(" refit" );
95- mSelK0 = ic.options ().get <bool >(" sel-k0" );
97+ mSelK0 = ic.options ().get <float >(" sel-k0" );
9698 mMaxEta = ic.options ().get <float >(" max-eta" );
9799}
98100
@@ -132,77 +134,108 @@ void SVStudySpec::updateTimeDependentParams(ProcessingContext& pc)
132134 mFitterV0 .setBz (mBz );
133135}
134136
135- void SVStudySpec::process ( o2::globaltracking::RecoContainer& recoData)
137+ o2::dataformats::V0Ext SVStudySpec::processV0 ( int iv, o2::globaltracking::RecoContainer& recoData)
136138{
139+ o2::dataformats::V0Ext v0ext;
140+ auto invalidate = [&v0ext]() { v0ext.v0ID .setVertexID (-1 ); };
141+
137142 auto v0s = recoData.getV0s ();
138143 auto v0IDs = recoData.getV0sIdx ();
139- bool refit = mRefit || (v0s.size () < v0IDs.size ());
140- int nv0 = v0IDs.size ();
141- o2::dataformats::V0 v0ref;
142- o2::track::TrackParCov dummyTr{};
143- const o2::track::TrackParCov* tpcTracks[2 ] = {&dummyTr, &dummyTr};
144- int nclTPC[2 ] = {0 , 0 }, nclITS[2 ] = {0 , 0 }, itsPatt[2 ] = {0 , 0 };
145- float chi2ITSTPC[2 ] = {-1 ., -1 .};
146144 static int tfID = 0 ;
147145
148- for (int iv = 0 ; iv < nv0; iv++) {
149- const auto & v0id = v0IDs[iv];
150- if (mRefit && !refitV0 (v0id, v0ref, recoData)) {
151- continue ;
152- }
153- const auto & v0 = mRefit ? v0ref : v0s[iv];
154- if (mMaxEta < std::abs (v0.getEta ())) {
155- continue ;
156- }
157- if (mSelK0 && std::abs (std::sqrt (v0.calcMass2AsK0 ()) - 0.497 ) > 0.1 ) {
158- continue ;
146+ const auto & v0id = v0IDs[iv];
147+ if (mRefit && !refitV0 (v0id, v0ext.v0 , recoData)) {
148+ invalidate ();
149+ return v0ext;
150+ }
151+ const auto & v0sel = mRefit ? v0ext.v0 : v0s[iv];
152+ if (mMaxEta < std::abs (v0sel.getEta ())) {
153+ invalidate ();
154+ return v0ext;
155+ }
156+ if (mSelK0 > 0 && std::abs (std::sqrt (v0sel.calcMass2AsK0 ()) - 0.497 ) > mSelK0 ) {
157+ invalidate ();
158+ return v0ext;
159+ }
160+ v0ext.v0ID = v0id;
161+ for (int ip = 0 ; ip < 2 ; ip++) {
162+ auto & prInfo = v0ext.prInfo [ip];
163+ auto gid = v0ext.v0ID .getProngID (ip);
164+ auto gidset = recoData.getSingleDetectorRefs (gid);
165+ // get TPC tracks, if any
166+ if (gidset[GTrackID::TPC].isSourceSet ()) {
167+ const auto & tpcTr = recoData.getTPCTrack (gidset[GTrackID::TPC]);
168+ prInfo.trackTPC = tpcTr;
169+ prInfo.nClTPC = tpcTr.getNClusters ();
159170 }
160- for (int ip = 0 ; ip < 2 ; ip++) {
161- auto gid = v0id.getProngID (ip);
162- auto gidset = recoData.getSingleDetectorRefs (gid);
163- // get TPC tracks, if any
164- tpcTracks[ip] = &dummyTr;
165- nclTPC[ip] = 0 ;
166- if (gidset[GTrackID::TPC].isSourceSet ()) {
167- const auto & tpcTr = recoData.getTPCTrack (gidset[GTrackID::TPC]);
168- tpcTracks[ip] = &tpcTr;
169- nclTPC[ip] = tpcTr.getNClusters ();
170- }
171- // get ITS tracks, if any
172- nclITS[ip] = itsPatt[ip] = 0 ;
173- if (gid.includesDet (DetID::ITS)) {
174- auto gidITS = recoData.getITSContributorGID (gid);
175- if (gidset[GTrackID::ITS].isSourceSet ()) {
176- const auto & itsTr = recoData.getITSTrack (recoData.getITSContributorGID (gid));
177- nclITS[ip] = itsTr.getNClusters ();
178- for (int il = 0 ; il < 7 ; il++) {
179- if (itsTr.hasHitOnLayer (il)) {
180- itsPatt[ip] |= 0x1 << il;
181- }
171+ // get ITS tracks, if any
172+ if (gid.includesDet (DetID::ITS)) {
173+ auto gidITS = recoData.getITSContributorGID (gid);
174+ if (gidset[GTrackID::ITS].isSourceSet ()) {
175+ const auto & itsTr = recoData.getITSTrack (recoData.getITSContributorGID (gid));
176+ prInfo.nClITS = itsTr.getNClusters ();
177+ for (int il = 0 ; il < 7 ; il++) {
178+ if (itsTr.hasHitOnLayer (il)) {
179+ prInfo.pattITS |= 0x1 << il;
182180 }
183- } else {
184- const auto & itsTrf = recoData. getITSABRefs ()[gidset[GTrackID::ITSAB]];
185- nclITS[ip] = itsTrf. getNClusters () ;
186- for ( int il = 0 ; il < 7 ; il++) {
187- if (itsTrf. hasHitOnLayer (il) ) {
188- itsPatt[ip] |= 0x1 << il;
189- }
181+ }
182+ } else {
183+ const auto & itsTrf = recoData. getITSABRefs ()[gidset[GTrackID::ITSAB]] ;
184+ prInfo. nClITS = itsTrf. getNClusters ();
185+ for ( int il = 0 ; il < 7 ; il++ ) {
186+ if (itsTrf. hasHitOnLayer (il)) {
187+ prInfo. pattITS |= 0x1 << il;
190188 }
191189 }
190+ prInfo.pattITS |= 0x1 << 31 ; // flag AB
192191 }
193192 if (gidset[GTrackID::ITSTPC].isSourceSet ()) {
194193 auto mtc = recoData.getTPCITSTrack (gidset[GTrackID::ITSTPC]);
195- chi2ITSTPC[ip] = mtc.getChi2Match ();
194+ prInfo.chi2ITSTPC = mtc.getChi2Match ();
195+ }
196+ }
197+ }
198+ return v0ext;
199+ }
200+
201+ void SVStudySpec::process (o2::globaltracking::RecoContainer& recoData)
202+ {
203+ auto v0IDs = recoData.getV0sIdx ();
204+ auto nv0 = v0IDs.size ();
205+ if (nv0 > recoData.getV0s ().size ()) {
206+ mRefit = true ;
207+ }
208+ std::map<int , std::vector<int >> pv2sv;
209+ static int tfID = 0 ;
210+ for (int iv = 0 ; iv < nv0; iv++) {
211+ const auto v0id = v0IDs[iv];
212+ pv2sv[v0id.getVertexID ()].push_back (iv);
213+ }
214+ std::vector<o2::dataformats::V0Ext> v0extVec;
215+ for (auto it : pv2sv) {
216+ int pvID = it.first ;
217+ auto & vv = it.second ;
218+ if (pvID < 0 || vv.size () == 0 ) {
219+ continue ;
220+ }
221+ v0extVec.clear ();
222+ for (int iv0 : vv) {
223+ auto v0ext = processV0 (iv0, recoData);
224+ if (v0ext.v0ID .getVertexID () < 0 ) {
225+ continue ;
196226 }
227+ v0extVec.push_back (v0ext);
228+ }
229+ if (v0extVec.size ()) {
230+ const auto & pv = recoData.getPrimaryVertex (pvID);
231+ (*mDBGOut ) << " v0"
232+ << " orbit=" << recoData.startIR .orbit << " tfID=" << tfID
233+ << " v0Ext=" << v0extVec
234+ << " pv=" << pv
235+ << " \n " ;
197236 }
198- (*mDBGOut ) << " tfinfo"
199- << " orbit=" << recoData.startIR .orbit << " tfID=" << tfID << " \n " ;
200- (*mDBGOut ) << " v0s"
201- << " v0=" << v0 << " v0ID=" << v0id << " tpc0=" << *tpcTracks[0 ] << " tpc1=" << *tpcTracks[1 ]
202- << " nclTPC0=" << nclTPC[0 ] << " nclTPC1=" << nclTPC[1 ] << " nclITS0=" << nclITS[0 ] << " nclITS1=" << nclITS[1 ] << " itsPatt0=" << itsPatt[0 ] << " itsPatt1=" << itsPatt[1 ]
203- << " chi2ITSTPC0=" << chi2ITSTPC[0 ] << " chi2ITSTPC1=" << chi2ITSTPC[1 ] << " \n " ;
237+ tfID++;
204238 }
205- tfID++;
206239}
207240
208241bool SVStudySpec::refitV0 (const V0ID& id, o2::dataformats::V0& v0, o2::globaltracking::RecoContainer& recoData)
@@ -286,7 +319,7 @@ DataProcessorSpec getSVStudySpec(GTrackID::mask_t srcTracks, bool useMC)
286319 AlgorithmSpec{adaptFromTask<SVStudySpec>(dataRequest, ggRequest, srcTracks, useMC)},
287320 Options{
288321 {" refit" , VariantType::Bool, false , {" refit SVertices" }},
289- {" sel-k0" , VariantType::Bool, false , {" select K0s only " }},
322+ {" sel-k0" , VariantType::Float, - 1 . f , {" If positive, select K0s with this mass margin " }},
290323 {" max-eta" , VariantType::Float, 1 .2f , {" Cut on track eta" }},
291324 }};
292325}
0 commit comments