CMS 3D CMS Logo

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  isPhase2 = false;
29 
30  if (pset_.getParameter<std::string>("stripClusterProducer") != "") {
31  theStripClusterLabel = consumes<edmNew::DetSetVector<SiStripCluster> >(edm::InputTag(pset_.getParameter<std::string>("stripClusterProducer")));
32  if (selfUpdateSkipClusters_) theStripClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
33  }
34  if (pset_.getParameter<std::string>("pixelClusterProducer") != "") {
35  thePixelClusterLabel = consumes<edmNew::DetSetVector<SiPixelCluster> >(edm::InputTag(pset_.getParameter<std::string>("pixelClusterProducer")));
36  if (selfUpdateSkipClusters_) thePixelClusterMask = consumes<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>(iConfig.getParameter<edm::InputTag>("skipClusters"));
37  }
38  if (pset_.existsAs<std::string>("Phase2TrackerCluster1DProducer")) {
39  thePh2OTClusterLabel = consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(edm::InputTag(pset_.getParameter<std::string>("Phase2TrackerCluster1DProducer")));
40  isPhase2 = true;
41  }
42 
43  produces<MeasurementTrackerEvent>();
44 }
45 
46 void
48 {
50  iSetup.get<CkfComponentsRecord>().get(measurementTrackerLabel_, measurementTracker);
51 
52  // create new data structures from templates
53  auto stripData = std::make_unique<StMeasurementDetSet>(measurementTracker->stripDetConditions());
54  auto pixelData= std::make_unique<PxMeasurementDetSet>(measurementTracker->pixelDetConditions());
55  auto phase2OTData = std::make_unique<Phase2OTMeasurementDetSet>(measurementTracker->phase2DetConditions());
56  std::vector<bool> stripClustersToSkip;
57  std::vector<bool> pixelClustersToSkip;
58  std::vector<bool> phase2ClustersToSkip;
59  // fill them
60  updateStrips(iEvent, *stripData, stripClustersToSkip);
61  updatePixels(iEvent, *pixelData, pixelClustersToSkip);
62  updatePhase2OT(iEvent, *phase2OTData);
63  updateStacks(iEvent, *phase2OTData);
64 
65  // put into MTE
66  // put into event
67  iEvent.put(std::move(
68  std::make_unique<MeasurementTrackerEvent>(*measurementTracker,
69  stripData.release(), pixelData.release(), phase2OTData.release(),
70  stripClustersToSkip, pixelClustersToSkip, phase2ClustersToSkip)
71  ));
72 }
73 
74 void
75 MeasurementTrackerEventProducer::updatePixels( const edm::Event& event, PxMeasurementDetSet & thePxDets, std::vector<bool> & pixelClustersToSkip ) const
76 {
77  // start by clearinng everything
78  thePxDets.setEmpty();
79 
80  bool switchOffPixelsIfEmpty = pset_.getParameter<bool>("switchOffPixelsIfEmpty");
81  std::vector<uint32_t> rawInactiveDetIds;
82  if (!theInactivePixelDetectorLabels.empty()) {
85  if (event.getByToken(tk, detIds)){
86  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
87  }else{
88  static std::atomic<bool> iFailedAlready{false};
89  bool expected = false;
90  if (iFailedAlready.compare_exchange_strong(expected,true,std::memory_order_acq_rel)){
91  edm::LogError("MissingProduct")<<"I fail to get the list of inactive pixel modules, because of 4.2/4.4 event content change.";
92  }
93  }
94  }
95  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
96  // mark as inactive if in rawInactiveDetIds
97  int i=0, endDet = thePxDets.size();
98  unsigned int idp=0;
99  for ( auto id : rawInactiveDetIds) {
100  if (id==idp) continue; // skip multiple id
101  idp=id;
102  i=thePxDets.find(id,i);
103  assert(i!=endDet && id == thePxDets.id(i));
104  thePxDets.setActiveThisEvent(i,false);
105  }
106  }
107 
108  // Pixel Clusters
110  if( pixelClusterProducer.empty() ) { //clusters have not been produced
111  if (switchOffPixelsIfEmpty) {
112  thePxDets.setActiveThisEvent(false);
113  }
114  }else{
115 
117  if(event.getByToken(thePixelClusterLabel, pixelClusters)) {
118 
119  const edmNew::DetSetVector<SiPixelCluster>* pixelCollection = pixelClusters.product();
120 
121 
122  if (switchOffPixelsIfEmpty && pixelCollection->empty()) {
123  thePxDets.setActiveThisEvent(false);
124  } else {
125 
126  //std::cout <<"updatePixels "<<pixelCollection->dataSize()<<std::endl;
127  pixelClustersToSkip.resize(pixelCollection->dataSize());
128  std::fill(pixelClustersToSkip.begin(),pixelClustersToSkip.end(),false);
129 
132  //and get the collection of pixel ref to skip
133  event.getByToken(thePixelClusterMask,pixelClusterMask);
134  LogDebug("MeasurementTracker")<<"getting pxl refs to skip";
135  if (pixelClusterMask.failedToGet())edm::LogError("MeasurementTracker")<<"not getting the pixel clusters to skip";
136  if (pixelClusterMask->refProd().id()!=pixelClusters.id()){
137  edm::LogError("ProductIdMismatch")<<"The pixel masking does not point to the proper collection of clusters: "<<pixelClusterMask->refProd().id()<<"!="<<pixelClusters.id();
138  }
139  pixelClusterMask->copyMaskTo(pixelClustersToSkip);
140  }
141 
142 
143  // FIXME: should check if lower_bound is better
144  int i = 0, endDet = thePxDets.size();
145  for (edmNew::DetSetVector<SiPixelCluster>::const_iterator it = pixelCollection->begin(), ed = pixelCollection->end(); it != ed; ++it) {
147  unsigned int id = set.id();
148  while ( id != thePxDets.id(i)) {
149  ++i;
150  if (endDet==i) throw "we have a problem!!!!";
151  }
152  // push cluster range in det
153  if ( thePxDets.isActive(i) ) {
154  thePxDets.update(i,set);
155  }
156  }
157  }
158  } else {
159  edm::LogWarning("MeasurementTrackerEventProducer") << "input pixel clusters collection " << pset_.getParameter<std::string>("pixelClusterProducer") << " is not valid";
160  }
161  }
162 }
163 
164 void
165 MeasurementTrackerEventProducer::updateStrips( const edm::Event& event, StMeasurementDetSet & theStDets, std::vector<bool> & stripClustersToSkip ) const
166 {
167  typedef edmNew::DetSet<SiStripCluster> StripDetSet;
168 
169  std::vector<uint32_t> rawInactiveDetIds;
170  getInactiveStrips(event,rawInactiveDetIds);
171 
172  // Strip Clusters
174  //first clear all of them
175  theStDets.setEmpty();
176 
177 
178  if( !stripClusterProducer.compare("") ) return; //clusters have not been produced
179 
180  const int endDet = theStDets.size();
181 
182 
183  // mark as inactive if in rawInactiveDetIds
184  int i=0;
185  unsigned int idp=0;
186  for ( auto id : rawInactiveDetIds) {
187  if (id==idp) continue; // skip multiple id
188  idp=id;
189  i=theStDets.find(id,i);
190  assert(i!=endDet && id == theStDets.id(i));
191  theStDets.setActiveThisEvent(i,false);
192  }
193 
194  //========= actually load cluster =============
195  {
197  if (event.getByToken(theStripClusterLabel, clusterHandle)) {
198  const edmNew::DetSetVector<SiStripCluster>* clusterCollection = clusterHandle.product();
199 
200 
203  //and get the collection of pixel ref to skip
204  LogDebug("MeasurementTracker")<<"getting strp refs to skip";
205  event.getByToken(theStripClusterMask,stripClusterMask);
206  if (stripClusterMask.failedToGet()) edm::LogError("MeasurementTracker")<<"not getting the strip clusters to skip";
207  if (stripClusterMask->refProd().id()!=clusterHandle.id()){
208  edm::LogError("ProductIdMismatch")<<"The strip masking does not point to the proper collection of clusters: "<<stripClusterMask->refProd().id()<<"!="<<clusterHandle.id();
209  }
210  stripClusterMask->copyMaskTo(stripClustersToSkip);
211  }
212 
213  theStDets.handle() = clusterHandle;
214  int i=0;
215  // cluster and det and in order (both) and unique so let's use set intersection
216  for ( auto j = 0U; j< (*clusterCollection).size(); ++j) {
217  unsigned int id = (*clusterCollection).id(j);
218  while ( id != theStDets.id(i)) { // eventually change to lower_bound
219  ++i;
220  if (endDet==i) throw "we have a problem in strips!!!!";
221  }
222 
223  // push cluster range in det
224  if ( theStDets.isActive(i) )
225  theStDets.update(i,j);
226  }
227  } else {
228  edm::LogWarning("MeasurementTrackerEventProducer") << "input strip cluster collection " << pset_.getParameter<std::string>("stripClusterProducer") << " is not valid";
229  }
230  }
231 }
232 
233 //FIXME: just a temporary solution for phase2!
234 void
236 
237 
238  // Phase2OT Clusters
239  if ( isPhase2 ) {
240 
241  std::string phase2ClusterProducer = pset_.getParameter<std::string>("Phase2TrackerCluster1DProducer");
242  if( phase2ClusterProducer.empty() ) { //clusters have not been produced
243  thePh2OTDets.setActiveThisEvent(false);
244  } else {
245 
247  if (event.getByToken(thePh2OTClusterLabel, phase2OTClusters)) {
248  const edmNew::DetSetVector<Phase2TrackerCluster1D>* phase2OTCollection = phase2OTClusters.product();
249 
250  int i = 0, endDet = thePh2OTDets.size();
251  for (edmNew::DetSetVector<Phase2TrackerCluster1D>::const_iterator it = phase2OTCollection->begin(), ed = phase2OTCollection->end(); it != ed; ++it) {
252 
254  unsigned int id = set.id();
255  while ( id != thePh2OTDets.id(i)) {
256  ++i;
257  if (endDet==i) throw "we have a problem!!!!";
258  }
259  // push cluster range in det
260  if ( thePh2OTDets.isActive(i) ) {
261  thePh2OTDets.update(i,set);
262  }
263  }
264  } else {
265  edm::LogWarning("MeasurementTrackerEventProducer") << "input Phase2TrackerCluster1D collection " << pset_.getParameter<std::string>("Phase2TrackerCluster1DProducer") << " is not valid";
266  }
267  }
268 
269  }
270  return;
271 }
272 
273 void
274 MeasurementTrackerEventProducer::getInactiveStrips(const edm::Event& event,std::vector<uint32_t> & rawInactiveDetIds) const
275 {
276  if (!theInactiveStripDetectorLabels.empty()) {
279  if (event.getByToken(tk, detIds)){
280  rawInactiveDetIds.insert(rawInactiveDetIds.end(), detIds->begin(), detIds->end());
281  }
282  }
283  if (!rawInactiveDetIds.empty()) std::sort(rawInactiveDetIds.begin(), rawInactiveDetIds.end());
284  }
285 
286 }
287 
288 
289 
#define LogDebug(id)
T getParameter(std::string const &) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
size_type dataSize() const
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactiveStripDetectorLabels
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
ProductID id() const
Definition: HandleBase.cc:15
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const_iterator end() const
Definition: EDCollection.h:153
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)
edm::EDGetTokenT< edmNew::DetSetVector< Phase2TrackerCluster1D > > thePh2OTClusterLabel
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
virtual const Phase2OTMeasurementConditionSet & phase2DetConditions() const =0
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
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 ...
void updatePhase2OT(const edm::Event &, Phase2OTMeasurementDetSet &thePh2OTDets) const
const edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > & handle() const
bool isActive(int i) const
void getInactiveStrips(const edm::Event &event, std::vector< uint32_t > &rawInactiveDetIds) const
void updateStacks(const edm::Event &, Phase2OTMeasurementDetSet &theStDets) const
void update(int i, const PixelDetSet &detSet)
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool failedToGet() const
Definition: HandleBase.h:78
const_iterator begin() const
Definition: EDCollection.h:146
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > > thePixelClusterMask
virtual const StMeasurementConditionSet & stripDetConditions() const =0
Provide templates to be filled in.
bool isActive(int i) const
void setActiveThisEvent(bool active)
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > theStripClusterLabel
id_type id() const
Definition: DetSetNew.h:81
virtual const PxMeasurementConditionSet & pixelDetConditions() const =0
int find(unsigned int jd, int i=0) const
void setActiveThisEvent(bool active)
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
unsigned int id(int i) const
void update(int i, const Phase2DetSet &detSet)
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > thePixelClusterLabel
def move(src, dest)
Definition: eostools.py:510
edm::EDGetTokenT< edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > > theStripClusterMask
const_iterator begin(bool update=false) const
std::vector< edm::EDGetTokenT< DetIdCollection > > theInactivePixelDetectorLabels
Definition: event.py:1