CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MeasurementTrackerEventProducer.cc
Go to the documentation of this file.
2 
5 
9 
11  measurementTrackerLabel_(iConfig.getParameter<std::string>("measurementTracker")),
12  pset_(iConfig)
13 {
14  std::vector<edm::InputTag> inactivePixelDetectorTags(iConfig.getParameter<std::vector<edm::InputTag> >("inactivePixelDetectorLabels"));
15  for (auto &t : inactivePixelDetectorTags) theInactivePixelDetectorLabels.push_back(consumes<DetIdCollection>(t));
16 
17  std::vector<edm::InputTag> inactiveStripDetectorTags(iConfig.getParameter<std::vector<edm::InputTag> >("inactiveStripDetectorLabels"));
18  for (auto &t : inactiveStripDetectorTags) theInactiveStripDetectorLabels.push_back(consumes<DetIdCollection>(t));
19 
20  //the measurement tracking is set to skip clusters, the other option is set from outside
21  selfUpdateSkipClusters_=iConfig.exists("skipClusters");
23  {
24  edm::InputTag skip=iConfig.getParameter<edm::InputTag>("skipClusters");
25  if (skip==edm::InputTag("")) selfUpdateSkipClusters_=false;
26  }
27  LogDebug("MeasurementTracker")<<"skipping clusters: "<<selfUpdateSkipClusters_;
28 
29  if (pset_.getParameter<std::string>("stripClusterProducer") != "") {
30  theStripClusterLabel = consumes<edmNew::DetSetVector<SiStripCluster> >(edm::InputTag(pset_.getParameter<std::string>("stripClusterProducer")));
31  if (selfUpdateSkipClusters_) theStripClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
32  }
33  if (pset_.getParameter<std::string>("pixelClusterProducer") != "") {
34  thePixelClusterLabel = consumes<edmNew::DetSetVector<SiPixelCluster> >(edm::InputTag(pset_.getParameter<std::string>("pixelClusterProducer")));
35  if (selfUpdateSkipClusters_) thePixelClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
36  }
37 
38  produces<MeasurementTrackerEvent>();
39 }
40 
41 void
43 {
45  iSetup.get<CkfComponentsRecord>().get(measurementTrackerLabel_, measurementTracker);
46 
47  // create new data structures from templates
48  std::auto_ptr<StMeasurementDetSet> stripData(new StMeasurementDetSet(measurementTracker->stripDetConditions()));
49  std::auto_ptr<PxMeasurementDetSet> pixelData(new PxMeasurementDetSet(measurementTracker->pixelDetConditions()));
50  //std::cout << "Created new strip data @" << &* stripData << std::endl;
51  std::vector<bool> stripClustersToSkip;
52  std::vector<bool> pixelClustersToSkip;
53 
54  // fill them
55  updateStrips(iEvent, *stripData, stripClustersToSkip);
56  updatePixels(iEvent, *pixelData, pixelClustersToSkip);
57 
58  // put into MTE
59  std::auto_ptr<MeasurementTrackerEvent> out(new MeasurementTrackerEvent(*measurementTracker, stripData.release(), pixelData.release(), stripClustersToSkip, pixelClustersToSkip));
60 
61  // put into event
62  iEvent.put(out);
63 }
64 
65 void
66 MeasurementTrackerEventProducer::updatePixels( const edm::Event& event, PxMeasurementDetSet & thePxDets, std::vector<bool> & pixelClustersToSkip ) const
67 {
68  // start by clearinng everything
69  thePxDets.setEmpty();
70 
71  bool switchOffPixelsIfEmpty = pset_.getParameter<bool>("switchOffPixelsIfEmpty");
72  std::vector<uint32_t> rawInactiveDetIds;
73  if (!theInactivePixelDetectorLabels.empty()) {
76  if (event.getByToken(tk, detIds)){
77  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
78  }else{
79  static std::atomic<bool> iFailedAlready{false};
80  bool expected = false;
81  if (iFailedAlready.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
82  edm::LogError("MissingProduct")<<"I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
83  }
84  }
85  }
86  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
87  // mark as inactive if in rawInactiveDetIds
88  int i=0, endDet = thePxDets.size();
89  unsigned int idp=0;
90  for ( auto id : rawInactiveDetIds) {
91  if (id==idp) continue; // skip multiple id
92  idp=id;
93  i=thePxDets.find(id,i);
94  assert(i!=endDet && id == thePxDets.id(i));
95  thePxDets.setActiveThisEvent(i,false);
96  }
97  }
98 
99  // Pixel Clusters
101  if( pixelClusterProducer.empty() ) { //clusters have not been produced
102  if (switchOffPixelsIfEmpty) {
103  thePxDets.setActiveThisEvent(false);
104  }
105  }else{
106 
108  event.getByToken(thePixelClusterLabel, pixelClusters);
109 
110  const edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
111 
112  if (switchOffPixelsIfEmpty && pixelCollection->empty()) {
113  thePxDets.setActiveThisEvent(false);
114  } else {
115 
116  //std::cout <<"updatePixels "<<pixelCollection->dataSize()<<std::endl;
117  pixelClustersToSkip.resize(pixelCollection->dataSize());
118  std::fill(pixelClustersToSkip.begin(),pixelClustersToSkip.end(),false);
119 
122  //and get the collection of pixel ref to skip
123  event.getByToken(thePixelClusterMask,pixelClusterMask);
124  LogDebug("MeasurementTracker")<<"getting pxl refs to skip";
125  if (pixelClusterMask.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the pixel clusters to skip";
126  if (pixelClusterMask->refProd().id()!=pixelClusters.id()){
127  edm::LogError("ProductIdMismatch")<<"The pixel masking does not point to the proper collection of clusters: "<<pixelClusterMask->refProd().id()<<"!="<<pixelClusters.id();
128  }
129  pixelClusterMask->copyMaskTo(pixelClustersToSkip);
130  }
131 
132 
133  // FIXME: should check if lower_bound is better
134  int i = 0, endDet = thePxDets.size();
135  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator it = pixelCollection->begin(), ed = pixelCollection->end(); it != ed; ++it) {
137  unsigned int id = set.id();
138  while ( id != thePxDets.id(i)) {
139  ++i;
140  if (endDet==i) throw "we have a problem!!!!";
141  }
142  // push cluster range in det
143  if ( thePxDets.isActive(i) ) {
144  thePxDets.update(i,set);
145  }
146  }
147  }
148  }
149 
150 }
151 
152 void
153 MeasurementTrackerEventProducer::updateStrips( const edm::Event& event, StMeasurementDetSet & theStDets, std::vector<bool> & stripClustersToSkip ) const
154 {
155  typedef edmNew::DetSet<SiStripCluster> StripDetSet;
156 
157  std::vector<uint32_t> rawInactiveDetIds;
158  getInactiveStrips(event,rawInactiveDetIds);
159 
160  // Strip Clusters
162  //first clear all of them
163  theStDets.setEmpty();
164 
165 
166  if( !stripClusterProducer.compare("") ) return; //clusters have not been produced
167 
168  const int endDet = theStDets.size();
169 
170 
171  // mark as inactive if in rawInactiveDetIds
172  int i=0;
173  unsigned int idp=0;
174  for ( auto id : rawInactiveDetIds) {
175  if (id==idp) continue; // skip multiple id
176  idp=id;
177  i=theStDets.find(id,i);
178  assert(i!=endDet && id == theStDets.id(i));
179  theStDets.setActiveThisEvent(i,false);
180  }
181 
182  //========= actually load cluster =============
183  {
185  event.getByToken(theStripClusterLabel, clusterHandle);
186  const edmNew::DetSetVector<SiStripCluster>* clusterCollection = clusterHandle.product();
187 
188 
191  //and get the collection of pixel ref to skip
192  LogDebug("MeasurementTracker")<<"getting strp refs to skip";
193  event.getByToken(theStripClusterMask,stripClusterMask);
194  if (stripClusterMask.failedToGet()) edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
195  if (stripClusterMask->refProd().id()!=clusterHandle.id()){
196  edm::LogError("ProductIdMismatch")<<"The strip masking does not point to the proper collection of clusters: "<<stripClusterMask->refProd().id()<<"!="<<clusterHandle.id();
197  }
198  stripClusterMask->copyMaskTo(stripClustersToSkip);
199  }
200 
201  theStDets.handle() = clusterHandle;
202  int i=0;
203  // cluster and det and in order (both) and unique so let's use set intersection
204  for ( auto j = 0U; j< (*clusterCollection).size(); ++j) {
205  unsigned int id = (*clusterCollection).id(j);
206  while ( id != theStDets.id(i)) { // eventually change to lower_bound
207  ++i;
208  if (endDet==i) throw "we have a problem in strips!!!!";
209  }
210 
211  // push cluster range in det
212  if ( theStDets.isActive(i) )
213  theStDets.update(i,j);
214  }
215  }
216 }
217 
218 void
219 MeasurementTrackerEventProducer::getInactiveStrips(const edm::Event& event,std::vector<uint32_t> & rawInactiveDetIds) const
220 {
221  if (!theInactiveStripDetectorLabels.empty()) {
224  if (event.getByToken(tk, detIds)){
225  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
226  }
227  }
228  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
229  }
230 
231 }
232 
233 
234 
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
size_type dataSize() const
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactiveStripDetectorLabels
string fill
Definition: lumiContext.py:319
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
tuple stripClusterProducer
tuple measurementTracker
assert(m_qm.get())
MeasurementTrackerEventProducer(const edm::ParameterSet &iConfig)
bool exists(std::string const &parameterName) const
checks if a parameter exists
void updateStrips(const edm::Event &, StMeasurementDetSet &theStDets, std::vector< bool > &stripClustersToSkip) const
void update(int i, const StripDetset &detSet)
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
void updatePixels(const edm::Event &, PxMeasurementDetSet &thePxDets, std::vector< bool > &pixelClustersToSkip) const
unsigned int id(int i) const
unsigned int id(int i) const
int find(unsigned int jd, int i=0) const
tuple pixelClusterProducer
int iEvent
Definition: GenABIO.cc:230
void setActiveThisEvent(int i, bool active)
Turn on/off the module for reconstruction for one events. This per-event flag is cleared by any call ...
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
bool isActive(int i) const
tuple switchOffPixelsIfEmpty
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
int j
Definition: DBlmapReader.cc:9
void update(int i, const PixelDetSet &detSet)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool failedToGet() const
Definition: HandleBase.h:79
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > > thePixelClusterMask
bool isActive(int i) const
tuple pixelClusters
void setActiveThisEvent(bool active)
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > theStripClusterLabel
id_type id() const
Definition: DetSetNew.h:81
int find(unsigned int jd, int i=0) const
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > thePixelClusterLabel
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > theStripClusterMask
const_iterator begin(bool update=false) const
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactivePixelDetectorLabels