00001
00002 #include "VisReco/VisTracker/interface/VisTkRecTrackDetsTwig.h"
00003 #include "VisFramework/VisEventSetup/interface/VisEventSetupService.h"
00004
00005 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00007 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00008 #include "VisFramework/VisConfigService/interface/VisConfigurationService.h"
00009
00010 #include "DataFormats/TrackReco/interface/Track.h"
00011 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00012 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00013 #include "DataFormats/TrackReco/interface/TrackBase.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017
00018 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00019 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00020 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00021
00022 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00023 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00024
00025 #include "Iguana/Models/interface/IgTextRep.h"
00026 #include "Iguana/GLModels/interface/Ig3DRep.h"
00027 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00028 #include "Iguana/GLModels/interface/IgRZRep.h"
00029 #include "Iguana/GLModels/interface/IgLegoRep.h"
00030 #include "Iguana/Framework/interface/IgRepSet.h"
00031 #include "Iguana/Studio/interface/IgQtLock.h"
00032
00033 #include <Inventor/nodes/SoMaterial.h>
00034 #include <Inventor/nodes/SoSeparator.h>
00035 #include <Inventor/nodes/SoDrawStyle.h>
00036 #include <qstring.h>
00037 #include <classlib/utils/Error.h>
00038 #include <sstream>
00039 #include <iomanip>
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 namespace
00052 {
00053 VisQueuedTwig *
00054 createThisTwig (IgState *state, IgTwig *parent,
00055 const std::string &name,
00056 const std::string &friendlyName,
00057 const std::string &modLabel,
00058 const std::string &instanceName,
00059 const std::string &processName)
00060 {
00061 return new VisTkRecTrackDetsTwig (state, parent, "Dets for reconstructed tracks (" + name + ")",
00062 friendlyName, modLabel, instanceName, processName);
00063 }
00064 }
00065
00066
00067
00068
00069 VisTkRecTrackDetsTwig::VisTkRecTrackDetsTwig (IgState *state, IgTwig *parent,
00070 const std::string &name ,
00071 const std::string &friendlyName ,
00072 const std::string &moduleLabel ,
00073 const std::string &instanceName ,
00074 const std::string &processName )
00075 : VisQueuedTwig (state, parent, name),
00076 m_text ("no info"),
00077 m_friendlyName (friendlyName),
00078 m_moduleLabel (moduleLabel),
00079 m_instanceName (instanceName),
00080 m_processName (processName)
00081 {
00082 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00083 if (! tfService)
00084 {
00085 tfService = new VisTwigFactroyService (state);
00086 }
00087 edm::TypeID trackID (typeid (reco::TrackCollection));
00088 tfService->registerTwig (trackID.friendlyClassName (), &createThisTwig);
00089 m_pset = VisConfigurationService::pSet ();
00090 if (! m_pset)
00091 {
00092 edm::ParameterSet p;
00093 VisConfigurationService *visService = new VisConfigurationService (p);
00094 m_pset = visService->pSet ();
00095 delete visService;
00096 }
00097
00098 std::vector<std::string> notSpecified;
00099 m_trackCollectionNames = m_pset->getUntrackedParameter<std::vector<std::string> > ("trackCollectionNames", notSpecified);
00100 }
00101
00102
00104 VisTkRecTrackDetsTwig::~VisTkRecTrackDetsTwig (void)
00105 {
00106 }
00107
00108 void
00109 VisTkRecTrackDetsTwig::onNewEvent (const edm::Event &event,
00110 const edm::EventSetup &eventSetup)
00111 {
00112
00113 VisQueuedTwig::onNewEvent (event, eventSetup);
00114
00115 m_geomDetUnits.clear ();
00116 std::vector<DetId> trackIds;
00117
00118 m_text = (QString ("Run # %1, event # %2")
00119 .arg (event.id ().run ())
00120 .arg (event.id ().event ()).latin1 ());
00121
00122 std::vector<edm::Handle<reco::TrackCollection> > trackCollections;
00123
00124 try
00125 {
00126 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00127 {
00128 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00129 event.getMany (visSel, trackCollections);
00130 }
00131 else
00132 {
00133 if (m_trackCollectionNames.empty ())
00134 event.getManyByType (trackCollections);
00135 else
00136 {
00137 for (std::vector<std::string>::iterator tkColl = m_trackCollectionNames.begin (), tkCollEnd = m_trackCollectionNames.end ();
00138 tkColl != tkCollEnd; ++tkColl)
00139 {
00140 LOG (2, trace, LFfwvis, "Getting track Collection with label " << (*tkColl) << "\n");
00141
00142 edm::Handle<reco::TrackCollection> tcHandle;
00143
00144 event.getByLabel ((*tkColl), tcHandle);
00145 trackCollections.push_back (tcHandle);
00146 }
00147 }
00148 }
00149 }
00150 catch (cms::Exception& e)
00151 {
00152 e.append (" from VisTkRecTrackDetsTwig: ");
00153 e.append (this->name ());
00154
00155 if (this->m_onCmsException)
00156 this->m_onCmsException (&e);
00157 }
00158 catch (lat::Error &e)
00159 {
00160 if (this->m_onError)
00161 this->m_onError (&e);
00162 }
00163 catch (std::exception &e)
00164 {
00165 if (this->m_onException)
00166 this->m_onException (&e);
00167 }
00168 catch (...)
00169 {
00170 if (this->m_onUnhandledException)
00171 this->m_onUnhandledException ();
00172 }
00173
00174 try
00175 {
00176 eventSetup.get<GlobalTrackingGeometryRecord> ().get (m_trackerGeometry);
00177 }
00178 catch (cms::Exception& e)
00179 {
00180 e.append (" from VisTkRecTrackDetsTwig: ");
00181 e.append (this->name ());
00182
00183 if (this->m_onCmsException)
00184 this->m_onCmsException (&e);
00185 }
00186 catch (lat::Error &e)
00187 {
00188 if (this->m_onError)
00189 this->m_onError (&e);
00190 }
00191 catch (std::exception &e)
00192 {
00193 if (this->m_onException)
00194 this->m_onException (&e);
00195 }
00196 catch (...)
00197 {
00198 if (this->m_onUnhandledException)
00199 this->m_onUnhandledException ();
00200 }
00201
00202 if ((! trackCollections.empty ()) && m_trackerGeometry.isValid ())
00203 {
00204 LOG (2, trace, LFfwvis, "OK: trackCollections is not empty and TrackingGeometry is valid===>>>\n");
00205
00206 std::vector<edm::Handle<reco::TrackCollection> >::iterator i;
00207 std::vector<edm::Handle<reco::TrackCollection> >::iterator iEnd;
00208
00209 LOG (2, trace, LFfwvis, "There are " << trackCollections.size () << " track collections.\n");
00210 int tc = 1;
00211 for (i = trackCollections.begin (), iEnd = trackCollections.end (); i != iEnd; ++i)
00212 {
00213 try
00214 {
00215 const reco::TrackCollection c = *(*i).product ();
00216 LOG (3, trace, LFfwvis, "#" << tc++ << ": track collection has " << c.size () << " tracks\n");
00217 for (reco::TrackCollection::const_iterator track = c.begin (), trackEnd = c.end (); track != trackEnd; ++track)
00218 {
00219 if ((*track).extra ().isNonnull ())
00220 {
00221 LOG (3, trace, LFfwvis, "\nTrack with rechitsize = " << (*track).recHitsSize ()
00222 << "\nCheck the validity of the RecHits:" << "\n");
00223
00224 bool valid = true;
00225 for (trackingRecHit_iterator it = track->recHitsBegin (), itEnd = track->recHitsEnd ();
00226 it != itEnd; ++it)
00227 {
00228 if ((*it)->geographicalId ().null ())
00229 {
00230 LOG (3, trace, LFfwvis, "\nWARNING: RecHit is not valid.\n");
00231 valid = false;
00232 }
00233 else
00234 {
00235 LOG (3, trace, LFfwvis, "\nRecHit is OK."
00236 << "\nPut id into trackIds.\n");
00237
00238 trackIds.push_back ((*it)->geographicalId ());
00239 }
00240 }
00241 }
00242 else
00243 {
00244 LOG (3, trace, LFfwvis, "\nTrack has no Extras stored.\n");
00245 }
00246 }
00247
00248 }
00249 catch (cms::Exception& e)
00250 {
00251 e.append (" from VisTkRecTrackDetsTwig: ");
00252 e.append (this->name ());
00253
00254 if (this->m_onCmsException)
00255 this->m_onCmsException (&e);
00256 }
00257 catch (lat::Error &e)
00258 {
00259 if (this->m_onError)
00260 this->m_onError (&e);
00261 }
00262 catch (std::exception &e)
00263 {
00264 if (this->m_onException)
00265 this->m_onException (&e);
00266 }
00267 catch (...)
00268 {
00269 if (this->m_onUnhandledException)
00270 this->m_onUnhandledException ();
00271 }
00272 }
00273 }
00274 else
00275 {
00276 LOG (2, trace, LFfwvis, "Hmmm.. trackCollections is empty or GlobalTrackingGeometry is not valid.\n");
00277 }
00278
00279 int nselected = 0;
00280
00281 std::vector<DetId> cleanedDetIds;
00282 std::vector<DetId>::const_iterator iter;
00283 std::vector<DetId>::const_iterator jter;
00284 std::vector<DetId>::const_iterator iterEnd = trackIds.end ();
00285
00286 try
00287 {
00288 for (iter = trackIds.begin (); iter != iterEnd; ++iter)
00289 {
00290 bool hasDup = false;
00291 for (jter = iter + 1; jter != iterEnd; ++jter)
00292 {
00293 if (*iter == *jter) hasDup = true;
00294 }
00295 if (! hasDup) cleanedDetIds.push_back (*iter);
00296 }
00297 }
00298 catch (cms::Exception& e)
00299 {
00300 e.append (" from VisTkRecTrackDetsTwig: ");
00301 e.append (this->name ());
00302
00303 if (this->m_onCmsException)
00304 this->m_onCmsException (&e);
00305 }
00306 catch (lat::Error &e)
00307 {
00308 if (this->m_onError)
00309 this->m_onError (&e);
00310 }
00311 catch (std::exception &e)
00312 {
00313 if (this->m_onException)
00314 this->m_onException (&e);
00315 }
00316 catch (...)
00317 {
00318 if (this->m_onUnhandledException)
00319 this->m_onUnhandledException ();
00320 }
00321
00322 trackIds.clear ();
00323 trackIds.swap (cleanedDetIds);
00324
00325 for (std::vector<DetId>::const_iterator detIdObject = trackIds.begin (); detIdObject != trackIds.end (); ++detIdObject)
00326 {
00327 if (! (*detIdObject).null ())
00328 {
00329 const GeomDet *gd = 0;
00330
00331 unsigned int id = detIdObject->rawId ();
00332 try
00333 {
00334 gd = dynamic_cast<const GeomDet *>(m_trackerGeometry->idToDet (*detIdObject));
00335 }
00336 catch (cms::Exception& e)
00337 {
00338 e.append (" from VisTkRecTrackDetsTwig: ");
00339 e.append (this->name ());
00340
00341 if (this->m_onCmsException)
00342 this->m_onCmsException (&e);
00343 }
00344 catch (lat::Error &e)
00345 {
00346 if (this->m_onError)
00347 this->m_onError (&e);
00348 }
00349 catch (std::exception &e)
00350 {
00351 if (this->m_onException)
00352 this->m_onException (&e);
00353 }
00354 catch (...)
00355 {
00356 if (this->m_onUnhandledException)
00357 this->m_onUnhandledException ();
00358 }
00359
00360 if (gd != 0)
00361 {
00362 std::vector<const GeomDet*> comp = gd->components ();
00363
00364 if (comp.empty ())
00365 {
00366
00367 const GeomDetUnit * geoUnit = 0;
00368 try
00369 {
00370 geoUnit = dynamic_cast<const GeomDetUnit *>(m_trackerGeometry->idToDetUnit (*detIdObject));
00371 }
00372 catch (cms::Exception& e)
00373 {
00374 if (this->m_onCmsException)
00375 this->m_onCmsException (&e);
00376 }
00377
00378 if (geoUnit != 0)
00379 {
00380
00381 m_geomDetUnits.push_back(geoUnit);
00382 nselected++;
00383 }
00384 }
00385 if (comp.size () == 2)
00386 {
00387
00388 const GeomDetUnit * geoUnit1 =
00389 dynamic_cast<const GeomDetUnit*> (comp [0]);
00390 if (geoUnit1 != 0)
00391 {
00392
00393 m_geomDetUnits.push_back (geoUnit1);
00394 nselected++;
00395 }
00396
00397 const GeomDetUnit * geoUnit2 =
00398 dynamic_cast<const GeomDetUnit*>(comp [1]);
00399 if (geoUnit2 != 0)
00400 {
00401
00402 m_geomDetUnits.push_back (geoUnit2);
00403 nselected++;
00404 }
00405 }
00406
00407 if (comp.size () == 1 || comp.size () > 2)
00408 {
00409 std::cout<<"module " << id << " intersected by rechit not found!"<<std::endl;
00410 }
00411 }
00412 else
00413 {
00414 std::cout<<"module " << id << " intersected by rechit not found!"<<std::endl;
00415 }
00416 }
00417 }
00418
00419
00420
00421 VisQueuedTwig::onBaseInvalidate ();
00422 }
00423
00424 void
00425 VisTkRecTrackDetsTwig::update (IgTextRep *rep)
00426 {
00427
00428
00429 }
00430
00431 void
00432 VisTkRecTrackDetsTwig::update (Ig3DRep *rep)
00433 {
00434
00435 VisQueuedTwig::update (rep);
00436
00437 IgQtLock ();
00438 rep->clear ();
00439
00440 if ((! m_geomDetUnits.empty ()) && m_trackerGeometry.isValid () )
00441 {
00442 VisEventSetupService *esService = VisEventSetupService::get (state ());
00443 ASSERT (esService);
00444
00445 SoSeparator* sep = esService->buildDet (VisEventSetupService::FullDet, m_geomDetUnits);
00446 if (sep != NULL)
00447 rep->node ()->addChild (sep);
00448 }
00449 }
00450
00451 void
00452 VisTkRecTrackDetsTwig::update (IgRPhiRep *rep)
00453 {
00454
00455 VisQueuedTwig::update (rep);
00456
00457 IgQtLock ();
00458 rep->clear ();
00459
00460 if ((! m_geomDetUnits.empty ()) && m_trackerGeometry.isValid () )
00461 {
00462 VisEventSetupService *esService = VisEventSetupService::get (state ());
00463 ASSERT (esService);
00464
00465 SoSeparator* sep = esService->buildDet (VisEventSetupService::RPhiDet, m_geomDetUnits);
00466
00467 sep->ref ();
00468 rep->node ()->addChild (sep);
00469 }
00470 }
00471
00472 void
00473 VisTkRecTrackDetsTwig::update (IgRZRep *rep)
00474 {
00475
00476 VisQueuedTwig::update (rep);
00477
00478 IgQtLock ();
00479 rep->clear ();
00480 if ((! m_geomDetUnits.empty ()) && m_trackerGeometry.isValid () )
00481 {
00482 VisEventSetupService *esService = VisEventSetupService::get (state ());
00483 ASSERT (esService);
00484
00485 SoSeparator* sep = esService->buildDet (VisEventSetupService::RZDet, m_geomDetUnits);
00486
00487 sep->ref ();
00488 rep->node ()->addChild (sep);
00489 }
00490
00491 }
00492
00493
00494 void
00495 VisTkRecTrackDetsTwig::update (IgLegoRep *rep)
00496 {
00497
00498
00499 VisQueuedTwig::update (rep);
00500
00501 IgQtLock ();
00502 rep->clear ();
00503
00504
00505 }
00506