CMS 3D CMS Logo

CTPPSPixelDQMSource.cc
Go to the documentation of this file.
1 /******************************************
2 *
3 * This is a part of CTPPSDQM software.
4 * Authors:
5 * F.Ferro INFN Genova
6 * Vladimir Popov (vladimir.popov@cern.ch)
7 *
8 *******************************************/
9 
16 
20 
22 
26 
27 #include <string>
28 
29 //-----------------------------------------------------------------------------
30 
32 {
33  public:
35  virtual ~CTPPSPixelDQMSource();
36 
37  protected:
38  void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
39  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
40  void analyze(edm::Event const& e, edm::EventSetup const& eSetup);
42  void endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& eSetup);
43  void endRun(edm::Run const& run, edm::EventSetup const& eSetup);
44 
45  private:
46  unsigned int verbosity;
47 
49 // edm::EDGetTokenT< edm::DetSetVector<CTPPSPixelCluster> > tokenCluster;
50 
51  static constexpr int NArms=2;
52  static constexpr int NStationMAX=3; // in an arm
53  static constexpr int NRPotsMAX=6; // per station
54  static constexpr int NplaneMAX=6; // per RPot
55  static constexpr int NROCsMAX = 6; // per plane
56  const int RPn_first = 3, RPn_last = 4;
57  const int hitMultMAX = 300;
58  const int ClusMultMAX = 90; // tuned
59  const int CluSizeMAX = 25; // tuned
60 
62  int pixRowMAX = 160; // defaultDetSizeInX, CMS Y-axis
63  int pixColMAX = 156; // defaultDetSizeInY, CMS X-axis
64  int ROCSizeInX = pixRowMAX/2; // ROC row size in pixels = 80
65  int ROCSizeInY = pixColMAX/3; // ROC col size in pixels = 52
66  long int nEvents = 0;
67 
69 
75 
76  static constexpr int RPotsTotalNumber=NArms*NStationMAX*NRPotsMAX;
77 
90  int HitsMultROC[RPotsTotalNumber*NplaneMAX][NROCsMAX];
92 
93 
94  unsigned int rpStatusWord = 0x8000; // 220 fr_hr (stn2rp3)
95  int RPstatus[NStationMAX][NRPotsMAX]; // symmetric in both arms
96  int StationStatus[NStationMAX]; // symmetric in both arms
97  const int IndexNotValid = 0;
98 
99  int getRPindex(int arm, int station, int rp) {
100  if(arm<0 || station<0 || rp<0) return(IndexNotValid);
101  if(arm>1 || station>=NStationMAX || rp>=NRPotsMAX) return(IndexNotValid);
102  int rc = (arm*NStationMAX+station)*NRPotsMAX + rp;
103  return(rc);
104  }
105 
106  int getPlaneIndex(int arm, int station, int rp, int plane) {
107  if(plane<0 || plane>=NplaneMAX) return(IndexNotValid);
108  int rc = getRPindex(arm, station, rp);
109  if(rc == IndexNotValid) return(IndexNotValid);
110  return(rc*NplaneMAX + plane);
111  }
112 
113  int prIndex(int rp, int plane) // plane index in station
114  {return((rp - RPn_first)*NplaneMAX + plane);}
115  int getDet(int id)
116  { return (id>>DetId::kDetOffset)&0xF; }
117  int getPixPlane(int id)
118  { return ((id>>16)&0x7); }
119 // int getSubdet(int id) { return ((id>>kSubdetOffset)&0x7); }
120 
121  int multHits, multClus, cluSizeMaxData; // for tuning
122 
123 };
124 
127 
128 //----------------------------------------------------------------------------------
129 
130 using namespace std;
131 using namespace edm;
132 
133 //-------------------------------------------------------------------------------
134 
136  verbosity(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
137  rpStatusWord(ps.getUntrackedParameter<unsigned int>("RPStatusWord",0x8000))
138 {
139  tokenDigi = consumes<DetSetVector<CTPPSPixelDigi> >(ps.getParameter<edm::InputTag>("tagRPixDigi"));
140 // tokenCluster=consumes<DetSetVector<CTPPSPixelCluster>>(ps.getParameter<edm::InputTag>("tagRPixCluster"));
141 
142 }
143 
144 //----------------------------------------------------------------------------------
145 
147 {
148 }
149 
150 //--------------------------------------------------------------------------
151 
153 {
154  if(verbosity) LogPrint("CTPPSPixelDQMSource") <<"RPstatusWord= "<<rpStatusWord;
155  nEvents = 0;
156 
159  ROCSizeInX = pixRowMAX/2; // ROC row size in pixels = 80
160  ROCSizeInY = pixColMAX/3;
161 
162  unsigned int rpSts = rpStatusWord<<1;
163  for(int stn=0; stn<3; stn++) {
164  int stns = 0;
165  for(int rp=0; rp<NRPotsMAX; rp++) {
166  rpSts = (rpSts >> 1); RPstatus[stn][rp] = rpSts&1;
167  if(RPstatus[stn][rp] > 0) stns = 1;
168  }
169  StationStatus[stn]=stns;
170  }
171 
172  for(int ind=0; ind<2*3*NRPotsMAX; ind++) RPindexValid[ind] = 0;
173 
175 }
176 
177 //-------------------------------------------------------------------------------------
178 
180 edm::EventSetup const &)
181 {
182  ibooker.cd();
183  ibooker.setCurrentFolder("CTPPS/TrackingPixel");
184  char s[50];
185  hBX = ibooker.book1D("events per BX", "ctpps_pixel;Event.BX", 4002, -1.5, 4000. +0.5);
186  hBXshort = ibooker.book1D("events per BX(short)", "ctpps_pixel;Event.BX", 102, -1.5, 100. + 0.5);
187 
188  for(int arm=0; arm<2; arm++) {
190  string sd, armTitle;
191  ID.armName(sd, CTPPSDetId::nPath);
192  ID.armName(armTitle, CTPPSDetId::nFull);
193 
194  ibooker.setCurrentFolder(sd);
195 
196  for(int stn=2; stn<NStationMAX; stn++) {
197  if(StationStatus[stn]==0) continue;
198  ID.setStation(stn);
199  string stnd, stnTitle;
200 
201  CTPPSDetId(ID.getStationId()).stationName(stnd, CTPPSDetId::nPath);
202  CTPPSDetId(ID.getStationId()).stationName(stnTitle, CTPPSDetId::nFull);
203 
204  ibooker.setCurrentFolder(stnd);
205 
206  string st = "planes activity";
207  string st2 = ": " + stnTitle;
208 
209  int rpnbins = RPn_last-RPn_first;
210 
211  h2PlaneActive[arm][stn] = ibooker.book2DD(st,st+st2+";Plane #",
212  NplaneMAX,0,NplaneMAX, rpnbins, RPn_first,RPn_last);
213  TH2D *h = h2PlaneActive[arm][stn]->getTH2D();
214  h->SetOption("colz");
215  TAxis *yah = h->GetYaxis();
216 
217  st = "hit average multiplicity in planes";
218 
219  hp2HitsOcc[arm][stn]= ibooker.bookProfile2D(st,st+st2+";Plane #",
220  NplaneMAX, 0, NplaneMAX, rpnbins, RPn_first,RPn_last,0,20000);
221  TProfile2D *h2 = hp2HitsOcc[arm][stn]->getTProfile2D();
222  h2->SetOption("textcolz");
223  TAxis *yah2 = h2->GetYaxis();
224 
225  int xmax = NplaneMAX*rpnbins;
226 
227  st = "hit multiplicity in planes";
228  string st3 = ";PlaneIndex(=pixelPot*PlaneMAX + plane)";
229  h2HitsMultipl[arm][stn]= ibooker.book2DD(st,st+st2+st3+";multiplicity",
230  xmax,0,xmax,hitMultMAX,0,hitMultMAX);
231  h2HitsMultipl[arm][stn]->getTH2D()->SetOption("colz");
232 
233  st = "cluster multiplicity in planes";
234  h2ClusMultipl[arm][stn] = ibooker.book2DD(st,st+st2+st3+";multiplicity",
235  xmax,0,xmax, ClusMultMAX,0,ClusMultMAX);
236  h2ClusMultipl[arm][stn]->getTH2D()->SetOption("colz");
237 
238  st = "cluster size in planes";
239  h2CluSize[arm][stn] = ibooker.book2D(st,st+st2+st3+";Cluster size",
240  xmax,0,xmax, CluSizeMAX,0,CluSizeMAX);
241  h2CluSize[arm][stn]->getTH2F()->SetOption("colz");
242 
243 //--------- Hits ---
244  int pixBinW = 4;
245  for(int rp=RPn_first; rp<RPn_last; rp++) { // only installed pixel pots
246  ID.setRP(rp);
247  string rpd, rpTitle;
248  CTPPSDetId(ID.getRPId()).rpName(rpTitle, CTPPSDetId::nShort);
249  yah->SetBinLabel(rp - RPn_first +1, rpTitle.c_str()); // h
250  yah2->SetBinLabel(rp - RPn_first +1, rpTitle.c_str()); //h2
251 
252  if(RPstatus[stn][rp]==0) continue;
253  int indexP = getRPindex(arm,stn,rp);
254  RPindexValid[indexP] = 1;
255 
256  CTPPSDetId(ID.getRPId()).rpName(rpTitle, CTPPSDetId::nFull);
257  CTPPSDetId(ID.getRPId()).rpName(rpd, CTPPSDetId::nPath);
258 
259  ibooker.setCurrentFolder(rpd);
260 
261  hRPotActivPlanes[indexP] =
262  ibooker.book1D("number of fired planes per event", rpTitle+";nPlanes",
263  NplaneMAX, -0.5, NplaneMAX+0.5);
264  hRPotActivBX[indexP] =
265  ibooker.book1D("5 fired planes per BX", rpTitle+";Event.BX", 4002, -1.5, 4000.+0.5);
266  hRPotActivBXroc[indexP] =
267  ibooker.book1D("4 fired ROCs per BX", rpTitle+";Event.BX", 4002, -1.5, 4000.+0.5);
268 
269  h2HitsMultROC[indexP] = ibooker.bookProfile2D("ROCs hits multiplicity per event",
270  rpTitle+";plane # ;ROC #", NplaneMAX,-0.5,NplaneMAX-0.5, NROCsMAX,-0.5,NROCsMAX-0.5, 100,0,1.e3);
271 
272  h2HitsMultROC[indexP]->getTProfile2D()->SetOption("colztext");
273  h2HitsMultROC[indexP]->getTProfile2D()->SetMinimum(1.e-10);
274 
275  hRPotActivROCs[indexP] = ibooker.book2D("number of fired aligned_ROCs per event",
276  rpTitle+";ROC ID;number of fired ROCs", NROCsMAX,-0.5,NROCsMAX-0.5, 7,-0.5,6.5);
277  hRPotActivROCs[indexP]->getTH2F()->SetOption("colz");
278 
279  hRPotActivROCsMax[indexP]= ibooker.book2D("max number of fired aligned_ROCs per event",
280  rpTitle+";ROC ID;number of fired ROCs", NROCsMAX,-0.5,NROCsMAX-0.5, 7,-0.5,6.5);
281  hRPotActivROCsMax[indexP]->getTH2F()->SetOption("colz");
282 
283  int nbins = pixRowMAX/pixBinW;
284 
285  for(int p=0; p<NplaneMAX; p++) {
286  sprintf(s,"plane_%d",p);
287  string pd = rpd+"/"+string(s);
288  ibooker.setCurrentFolder(pd);
289  string st1 = ": "+rpTitle+"_"+string(s);
290  st = "hits position";
291  h2xyHits[indexP][p]=ibooker.book2DD(st,st1+";pix col;pix row",
292  nbins,0,pixRowMAX,nbins,0,pixRowMAX);
293  h2xyHits[indexP][p]->getTH2D()->SetOption("colz");
294 
295  st = "adc average value";
296  hp2xyADC[indexP][p]=ibooker.bookProfile2D(st,st1+";pix col;pix row",
297  nbins,0,pixRowMAX,nbins,0,pixRowMAX,100,0,1.e10,"");
298  hp2xyADC[indexP][p]->getTProfile2D()->SetOption("colz");
299 
300  st = "hits multiplicity";
301  hHitsMult[indexP][p]=ibooker.book1DD(st,st1+";number of hits;N / 1 hit",
303 
304  ibooker.setCurrentFolder(pd + "/ROCs");
305  int index = getPlaneIndex(arm,stn,rp,p);
306 
307  for(int roc=0; roc<6; roc++) {
308  sprintf(s,"ROC_%d",roc);
309  string st2 = st1 + "_" + string(s);
310  ibooker.setCurrentFolder(pd + "/ROCs/" + string(s));
311 
312  h2xyROCHits[index][roc]=ibooker.book2DD("hits",st2+";pix row;pix col",
314  h2xyROCHits[index][roc]->getTH2D()->SetOption("colz");
315 
316  string st = "adc average value";
317  h2xyROCadc[index][roc]=ibooker.bookProfile2D(st,st2+";pix row;pix col",
319  h2xyROCadc[index][roc]->getTProfile2D()->SetOption("colz");
320  }
321  } // end of for(int p=0; p<NplaneMAX;..
322 
323  } // end for(int rp=0; rp<NRPotsMAX;...
324  } // end of for(int stn=0; stn<
325  } //end of for(int arm=0; arm<2;...
326 
327  return;
328 }
329 
330 //-------------------------------------------------------------------------------
332  edm::EventSetup const& context)
333 {
334 }
335 //---------------------------------------------------------------------------------
336 
338 {
339  ++nEvents;
340  int RPactivity[2][NRPotsMAX];
341  for(int arm = 0; arm <2; arm++) {
342  for(int rp=0; rp<NRPotsMAX; rp++) {
343  RPactivity[arm][rp] = 0;
344  }
345  }
346  for(int ind=0; ind<2*3*NRPotsMAX; ind++) {
347  for(int p=0; p<NplaneMAX; p++) {
348  HitsMultPlane[ind][p] = 0;
349  }
350  }
351  for(int ind=0; ind<2*3*NRPotsMAX*NplaneMAX; ind++) {
352  for(int rp=0; rp<NROCsMAX; rp++) {
353  HitsMultROC[ind][rp] = 0;
354  }
355  }
357  event.getByToken(tokenDigi, pixDigi);
358 
359  hBX->Fill(event.bunchCrossing());
360  hBXshort->Fill(event.bunchCrossing());
361 
362  bool valid = false;
363  valid |= pixDigi.isValid();
364 // valid |= Clus.isValid();
365 
366  if(!valid && verbosity) LogPrint("CTPPSPixelDQMSource") <<"No valid data in Event "<<nEvents;
367 
368  if(pixDigi.isValid()) {
369  for(const auto &ds_digi : *pixDigi) {
370  int idet = getDet(ds_digi.id);
371  if(idet != DetId::VeryForward) {
372  if(verbosity>1) LogPrint("CTPPSPixelDQMSource") <<"not CTPPS: ds_digi.id"<<ds_digi.id;
373  continue;
374  }
375  // int subdet = getSubdet(ds_digi.id);
376 
377  int plane = getPixPlane(ds_digi.id);
378 
379  CTPPSDetId theId(ds_digi.id);
380  int arm = theId.arm()&0x1;
381  int station = theId.station()&0x3;
382  int rpot = theId.rp()&0x7;
383  RPactivity[arm][rpot] = 1;
384 
385  if(StationStatus[station] && RPstatus[station][rpot]) {
386 
387  hp2HitsOcc[arm][station]->Fill(plane,rpot,(int)ds_digi.data.size());
388  h2HitsMultipl[arm][station]->Fill(prIndex(rpot,plane),ds_digi.data.size());
389  h2PlaneActive[arm][station]->Fill(plane,rpot);
390 
391  int index = getRPindex(arm,station,rpot);
392  HitsMultPlane[index][plane] += ds_digi.data.size();
393  if(RPindexValid[index]) {
394  hHitsMult[index][plane]->Fill(ds_digi.data.size());
395  }
396  int rocHistIndex = getPlaneIndex(arm,station,rpot,plane);
397 
398  for(DetSet<CTPPSPixelDigi>::const_iterator dit = ds_digi.begin();
399  dit != ds_digi.end(); ++dit) {
400  int row = dit->row();
401  int col = dit->column();
402  int adc = dit->adc();
403 
404  if(RPindexValid[index]) {
405  h2xyHits[index][plane]->Fill(col,row);
406  hp2xyADC[index][plane]->Fill(col,row,adc);
407  int colROC, rowROC;
408  int trocId;
409  if(!thePixIndices.transformToROC(col,row, trocId, colROC, rowROC)) {
410  if(trocId>=0 && trocId<NROCsMAX) {
411  h2xyROCHits[rocHistIndex][trocId]->Fill(rowROC,colROC);
412  h2xyROCadc[rocHistIndex][trocId]->Fill(rowROC,colROC,adc);
413  ++HitsMultROC[rocHistIndex][trocId];
414  }
415  }
416  } //end if(RPindexValid[index]) {
417  }
418 
419  if(int(ds_digi.data.size()) > multHits) multHits = ds_digi.data.size();
420  } // end if(StationStatus[station]) {
421  } // end for(const auto &ds_digi : *pixDigi)
422  } //if(pixDigi.isValid()) {
423 
424  for(int arm=0; arm<2; arm++) {
425  for(int stn=0; stn<NStationMAX; stn++) {
426  for(int rp=0; rp<NRPotsMAX; rp++) {
427  int index = getRPindex(arm,stn,rp);
428  if(RPindexValid[index]==0) continue;
429  if(RPactivity[arm][rp]==0) continue;
430 
431  int np = 0;
432  for(int p=0; p<NplaneMAX; p++) {
433  if(HitsMultPlane[index][p]>0) np++;
434  }
436  if(np>5) { hRPotActivBX[index]->Fill(event.bunchCrossing());}
437 
438  int rocf[NplaneMAX];
439  for(int r=0; r<NROCsMAX; r++) { rocf[r]=0; }
440  for(int p=0; p<NplaneMAX; p++) {
441  int indp = getPlaneIndex(arm,stn,rp,p);
442  for(int r=0; r<NROCsMAX; r++) {
443  if(HitsMultROC[indp][r] > 0) ++rocf[r];
444  }
445  for(int r=0; r<NROCsMAX; r++) {
446  h2HitsMultROC[index]->Fill(p,r,HitsMultROC[indp][r]);
447  }
448  }
449  int max = 0;
450  for(int r=0; r<NROCsMAX; r++) {
451  if(max < rocf[r]) { max = rocf[r]; }
452  }
453  for(int r=0; r<NROCsMAX; r++) {
454  hRPotActivROCs[index]->Fill(r,rocf[r]);
455  }
456  for(int r=0; r<NROCsMAX; r++) {
457  if(rocf[r] == max) {hRPotActivROCsMax[index]->Fill(r,max);}
458  }
459  if(max > 4) hRPotActivBXroc[index]->Fill(event.bunchCrossing());
460  }
461  }
462  }
463 
464  if((nEvents % 100)) return;
465  if(verbosity) LogPrint("CTPPSPixelDQMSource")<<"analyze event "<<nEvents;
466 }
467 
468 //--------------------------------------------------------------
470 {
471 }
472 
473 //-----------------------------------------------------------------------------
475 {
476  if(!verbosity) return;
477  LogPrint("CTPPSPixelDQMSource")
478  <<"end of Run "<<run.run()<<": "<<nEvents<<" events\n"
479  <<"mult Hits/Clus: "<<multHits<<" / "<<multClus
480  <<" cluSizeMaxData= "<<cluSizeMaxData;
481 }
482 
483 //---------------------------------------------------------------------------
485 
int adc(sample_type sample)
get the ADC sample (12 bits)
uint32_t station() const
Definition: CTPPSDetId.h:63
T getParameter(std::string const &) const
MonitorElement * hHitsMult[RPotsTotalNumber][NplaneMAX]
int HitsMultPlane[RPotsTotalNumber][NplaneMAX]
MonitorElement * hp2xyADC[RPotsTotalNumber][NplaneMAX]
MonitorElement * h2CluSize[NArms][NStationMAX]
RunNumber_t run() const
Definition: RunBase.h:40
edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelDigi > > tokenDigi
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
TProfile2D * getTProfile2D(void) const
MonitorElement * hp2HitsOcc[NArms][NStationMAX]
void cd(void)
Definition: DQMStore.cc:269
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * h2HitsMultROC[RPotsTotalNumber]
uint32_t ID
Definition: Definitions.h:26
void setRP(uint32_t rp)
Definition: CTPPSDetId.h:79
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &eSetup)
int bunchCrossing() const
Definition: EventBase.h:66
int getDefaultRowDetSize() const
MonitorElement * hRPotActivROCsMax[RPotsTotalNumber]
TH2D * getTH2D(void) const
CTPPSDetId getStationId() const
Definition: CTPPSDetId.h:92
CTPPSPixelIndices thePixIndices
#define constexpr
void Fill(long long x)
int prIndex(int rp, int plane)
int RPindexValid[RPotsTotalNumber]
int RPstatus[NStationMAX][NRPotsMAX]
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void endLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &eSetup)
int np
Definition: AMPTWrapper.h:33
MonitorElement * h2ClusMultipl[NArms][NStationMAX]
CTPPSPixelDQMSource(const edm::ParameterSet &ps)
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:163
MonitorElement * hRPotActivBX[RPotsTotalNumber]
int getDefaultColDetSize() const
MonitorElement * h2xyROCadc[RPotsTotalNumber *NplaneMAX][NROCsMAX]
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
uint32_t arm() const
Definition: CTPPSDetId.h:52
bool isValid() const
Definition: HandleBase.h:74
void armName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:115
int getRPindex(int arm, int station, int rp)
MonitorElement * hRPotActivBXroc[RPotsTotalNumber]
MonitorElement * h2PlaneActive[NArms][NStationMAX]
iterator begin()
Definition: DetSet.h:59
MonitorElement * h2xyROCHits[RPotsTotalNumber *NplaneMAX][NROCsMAX]
void setStation(uint32_t station)
Definition: CTPPSDetId.h:68
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
double sd
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
int transformToROC(const int col, const int row, int &rocId, int &colROC, int &rowROC) const
HLT enums.
static const int kDetOffset
Definition: DetId.h:20
MonitorElement * hRPotActivROCs[RPotsTotalNumber]
col
Definition: cuy.py:1008
MonitorElement * book2DD(Args &&...args)
Definition: DQMStore.h:145
int StationStatus[NStationMAX]
void analyze(edm::Event const &e, edm::EventSetup const &eSetup)
int HitsMultROC[RPotsTotalNumber *NplaneMAX][NROCsMAX]
TH2F * getTH2F(void) const
int getPlaneIndex(int arm, int station, int rp, int plane)
MonitorElement * h2xyHits[RPotsTotalNumber][NplaneMAX]
MonitorElement * hRPotActivPlanes[RPotsTotalNumber]
MonitorElement * book1DD(Args &&...args)
Definition: DQMStore.h:127
MonitorElement * hBXshort
MonitorElement * h2HitsMultipl[NArms][NStationMAX]
Definition: event.py:1
Definition: Run.h:42
uint32_t rp() const
Definition: CTPPSDetId.h:74