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 
125 //----------------------------------------------------------------------------------
126 
127 using namespace std;
128 using namespace edm;
129 
130 //-------------------------------------------------------------------------------
131 
133  verbosity(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
134  rpStatusWord(ps.getUntrackedParameter<unsigned int>("RPStatusWord",0x8000))
135 {
136  tokenDigi = consumes<DetSetVector<CTPPSPixelDigi> >(ps.getParameter<edm::InputTag>("tagRPixDigi"));
137 // tokenCluster=consumes<DetSetVector<CTPPSPixelCluster>>(ps.getParameter<edm::InputTag>("tagRPixCluster"));
138 
139 }
140 
141 //----------------------------------------------------------------------------------
142 
144 {
145 }
146 
147 //--------------------------------------------------------------------------
148 
150 {
151  if(verbosity) LogPrint("CTPPSPixelDQMSource") <<"RPstatusWord= "<<rpStatusWord;
152  nEvents = 0;
153 
156  ROCSizeInX = pixRowMAX/2; // ROC row size in pixels = 80
157  ROCSizeInY = pixColMAX/3;
158 
159  unsigned int rpSts = rpStatusWord<<1;
160  for(int stn=0; stn<3; stn++) {
161  int stns = 0;
162  for(int rp=0; rp<NRPotsMAX; rp++) {
163  rpSts = (rpSts >> 1); RPstatus[stn][rp] = rpSts&1;
164  if(RPstatus[stn][rp] > 0) stns = 1;
165  }
166  StationStatus[stn]=stns;
167  }
168 
169  for(int ind=0; ind<2*3*NRPotsMAX; ind++) RPindexValid[ind] = 0;
170 
172 }
173 
174 //-------------------------------------------------------------------------------------
175 
177 edm::EventSetup const &)
178 {
179  ibooker.cd();
180  ibooker.setCurrentFolder("CTPPS/TrackingPixel");
181  char s[50];
182  hBX = ibooker.book1D("events per BX", "ctpps_pixel;Event.BX", 4002, -1.5, 4000. +0.5);
183  hBXshort = ibooker.book1D("events per BX(short)", "ctpps_pixel;Event.BX", 102, -1.5, 100. + 0.5);
184 
185  for(int arm=0; arm<2; arm++) {
187  string sd, armTitle;
188  ID.armName(sd, CTPPSDetId::nPath);
189  ID.armName(armTitle, CTPPSDetId::nFull);
190 
191  ibooker.setCurrentFolder(sd);
192 
193  for(int stn=2; stn<NStationMAX; stn++) {
194  if(StationStatus[stn]==0) continue;
195  ID.setStation(stn);
196  string stnd, stnTitle;
197 
198  CTPPSDetId(ID.getStationId()).stationName(stnd, CTPPSDetId::nPath);
199  CTPPSDetId(ID.getStationId()).stationName(stnTitle, CTPPSDetId::nFull);
200 
201  ibooker.setCurrentFolder(stnd);
202 
203  string st = "planes activity";
204  string st2 = ": " + stnTitle;
205 
206  int rpnbins = RPn_last-RPn_first;
207 
208  h2PlaneActive[arm][stn] = ibooker.book2DD(st,st+st2+";Plane #",
209  NplaneMAX,0,NplaneMAX, rpnbins, RPn_first,RPn_last);
210  TH2D *h = h2PlaneActive[arm][stn]->getTH2D();
211  h->SetOption("colz");
212  TAxis *yah = h->GetYaxis();
213 
214  st = "hit average multiplicity in planes";
215 
216  hp2HitsOcc[arm][stn]= ibooker.bookProfile2D(st,st+st2+";Plane #",
217  NplaneMAX, 0, NplaneMAX, rpnbins, RPn_first,RPn_last,0,20000);
218  TProfile2D *h2 = hp2HitsOcc[arm][stn]->getTProfile2D();
219  h2->SetOption("textcolz");
220  TAxis *yah2 = h2->GetYaxis();
221 
222  int xmax = NplaneMAX*rpnbins;
223 
224  st = "hit multiplicity in planes";
225  string st3 = ";PlaneIndex(=pixelPot*PlaneMAX + plane)";
226  h2HitsMultipl[arm][stn]= ibooker.book2DD(st,st+st2+st3+";multiplicity",
227  xmax,0,xmax,hitMultMAX,0,hitMultMAX);
228  h2HitsMultipl[arm][stn]->getTH2D()->SetOption("colz");
229 
230  st = "cluster multiplicity in planes";
231  h2ClusMultipl[arm][stn] = ibooker.book2DD(st,st+st2+st3+";multiplicity",
232  xmax,0,xmax, ClusMultMAX,0,ClusMultMAX);
233  h2ClusMultipl[arm][stn]->getTH2D()->SetOption("colz");
234 
235  st = "cluster size in planes";
236  h2CluSize[arm][stn] = ibooker.book2D(st,st+st2+st3+";Cluster size",
237  xmax,0,xmax, CluSizeMAX,0,CluSizeMAX);
238  h2CluSize[arm][stn]->getTH2F()->SetOption("colz");
239 
240 //--------- Hits ---
241  int pixBinW = 4;
242  for(int rp=RPn_first; rp<RPn_last; rp++) { // only installed pixel pots
243  ID.setRP(rp);
244  string rpd, rpTitle;
245  CTPPSDetId(ID.getRPId()).rpName(rpTitle, CTPPSDetId::nShort);
246  yah->SetBinLabel(rp - RPn_first +1, rpTitle.c_str()); // h
247  yah2->SetBinLabel(rp - RPn_first +1, rpTitle.c_str()); //h2
248 
249  if(RPstatus[stn][rp]==0) continue;
250  int indexP = getRPindex(arm,stn,rp);
251  RPindexValid[indexP] = 1;
252 
253  CTPPSDetId(ID.getRPId()).rpName(rpTitle, CTPPSDetId::nFull);
254  CTPPSDetId(ID.getRPId()).rpName(rpd, CTPPSDetId::nPath);
255 
256  ibooker.setCurrentFolder(rpd);
257 
258  hRPotActivPlanes[indexP] =
259  ibooker.book1D("number of fired planes per event", rpTitle+";nPlanes",
260  NplaneMAX, -0.5, NplaneMAX+0.5);
261  hRPotActivBX[indexP] =
262  ibooker.book1D("5 fired planes per BX", rpTitle+";Event.BX", 4002, -1.5, 4000.+0.5);
263  hRPotActivBXroc[indexP] =
264  ibooker.book1D("4 fired ROCs per BX", rpTitle+";Event.BX", 4002, -1.5, 4000.+0.5);
265 
266  h2HitsMultROC[indexP] = ibooker.bookProfile2D("ROCs hits multiplicity per event",
267  rpTitle+";plane # ;ROC #", NplaneMAX,-0.5,NplaneMAX-0.5, NROCsMAX,-0.5,NROCsMAX-0.5, 100,0,1.e3);
268 
269  h2HitsMultROC[indexP]->getTProfile2D()->SetOption("colztext");
270  h2HitsMultROC[indexP]->getTProfile2D()->SetMinimum(1.e-10);
271 
272  hRPotActivROCs[indexP] = ibooker.book2D("number of fired aligned_ROCs per event",
273  rpTitle+";ROC ID;number of fired ROCs", NROCsMAX,-0.5,NROCsMAX-0.5, 7,-0.5,6.5);
274  hRPotActivROCs[indexP]->getTH2F()->SetOption("colz");
275 
276  hRPotActivROCsMax[indexP]= ibooker.book2D("max number of fired aligned_ROCs per event",
277  rpTitle+";ROC ID;number of fired ROCs", NROCsMAX,-0.5,NROCsMAX-0.5, 7,-0.5,6.5);
278  hRPotActivROCsMax[indexP]->getTH2F()->SetOption("colz");
279 
280  int nbins = pixRowMAX/pixBinW;
281 
282  for(int p=0; p<NplaneMAX; p++) {
283  sprintf(s,"plane_%d",p);
284  string pd = rpd+"/"+string(s);
285  ibooker.setCurrentFolder(pd);
286  string st1 = ": "+rpTitle+"_"+string(s);
287  st = "hits position";
288  h2xyHits[indexP][p]=ibooker.book2DD(st,st1+";pix col;pix row",
289  nbins,0,pixRowMAX,nbins,0,pixRowMAX);
290  h2xyHits[indexP][p]->getTH2D()->SetOption("colz");
291 
292  st = "adc average value";
293  hp2xyADC[indexP][p]=ibooker.bookProfile2D(st,st1+";pix col;pix row",
294  nbins,0,pixRowMAX,nbins,0,pixRowMAX,100,0,1.e10,"");
295  hp2xyADC[indexP][p]->getTProfile2D()->SetOption("colz");
296 
297  st = "hits multiplicity";
298  hHitsMult[indexP][p]=ibooker.book1DD(st,st1+";number of hits;N / 1 hit",
300 
301  ibooker.setCurrentFolder(pd + "/ROCs");
302  int index = getPlaneIndex(arm,stn,rp,p);
303 
304  for(int roc=0; roc<6; roc++) {
305  sprintf(s,"ROC_%d",roc);
306  string st2 = st1 + "_" + string(s);
307  ibooker.setCurrentFolder(pd + "/ROCs/" + string(s));
308 
309  h2xyROCHits[index][roc]=ibooker.book2DD("hits",st2+";pix row;pix col",
311  h2xyROCHits[index][roc]->getTH2D()->SetOption("colz");
312 
313  string st = "adc average value";
314  h2xyROCadc[index][roc]=ibooker.bookProfile2D(st,st2+";pix row;pix col",
316  h2xyROCadc[index][roc]->getTProfile2D()->SetOption("colz");
317  }
318  } // end of for(int p=0; p<NplaneMAX;..
319 
320  } // end for(int rp=0; rp<NRPotsMAX;...
321  } // end of for(int stn=0; stn<
322  } //end of for(int arm=0; arm<2;...
323 
324  return;
325 }
326 
327 //-------------------------------------------------------------------------------
329  edm::EventSetup const& context)
330 {
331 }
332 //---------------------------------------------------------------------------------
333 
335 {
336  ++nEvents;
337  int RPactivity[2][NRPotsMAX];
338  for(int arm = 0; arm <2; arm++) for(int rp=0; rp<NRPotsMAX; rp++)
339  RPactivity[arm][rp] = 0;
340  for(int ind=0; ind<2*3*NRPotsMAX; ind++)
341  for(int p=0; p<NplaneMAX; p++) HitsMultPlane[ind][p] = 0;
342 
343  for(int ind=0; ind<2*3*NRPotsMAX*NplaneMAX; ind++)
344  for(int rp=0; rp<NROCsMAX; rp++) HitsMultROC[ind][rp] = 0;
345 
347  event.getByToken(tokenDigi, pixDigi);
348 
349  hBX->Fill(event.bunchCrossing());
350  hBXshort->Fill(event.bunchCrossing());
351 
352  bool valid = false;
353  valid |= pixDigi.isValid();
354 // valid |= Clus.isValid();
355 
356  if(!valid && verbosity) LogPrint("CTPPSPixelDQMSource") <<"No valid data in Event "<<nEvents;
357 
358 if(pixDigi.isValid())
359  for(const auto &ds_digi : *pixDigi)
360  {
361  int idet = getDet(ds_digi.id);
362  if(idet != DetId::VeryForward) {
363  if(verbosity>1) LogPrint("CTPPSPixelDQMSource") <<"not CTPPS: ds_digi.id"<<ds_digi.id;
364  continue;
365  }
366 // int subdet = getSubdet(ds_digi.id);
367 
368  int plane = getPixPlane(ds_digi.id);
369 
370  CTPPSDetId theId(ds_digi.id);
371  int arm = theId.arm()&0x1;
372  int station = theId.station()&0x3;
373  int rpot = theId.rp()&0x7;
374  RPactivity[arm][rpot] = 1;
375 
376  if(StationStatus[station] && RPstatus[station][rpot]) {
377 
378  hp2HitsOcc[arm][station]->Fill(plane,rpot,(int)ds_digi.data.size());
379  h2HitsMultipl[arm][station]->Fill(prIndex(rpot,plane),ds_digi.data.size());
380  h2PlaneActive[arm][station]->Fill(plane,rpot);
381 
382  int index = getRPindex(arm,station,rpot);
383  HitsMultPlane[index][plane] += ds_digi.data.size();
384  if(RPindexValid[index])
385  hHitsMult[index][plane]->Fill(ds_digi.data.size());
386  int rocHistIndex = getPlaneIndex(arm,station,rpot,plane);
387 
388  for(DetSet<CTPPSPixelDigi>::const_iterator dit = ds_digi.begin();
389  dit != ds_digi.end(); ++dit) {
390  int row = dit->row();
391  int col = dit->column();
392  int adc = dit->adc();
393 
394  if(RPindexValid[index]) {
395  h2xyHits[index][plane]->Fill(col,row);
396  hp2xyADC[index][plane]->Fill(col,row,adc);
397  int colROC, rowROC;
398  int trocId;
399  if(!thePixIndices.transformToROC(col,row, trocId, colROC, rowROC)) {
400  if(trocId>=0 && trocId<NROCsMAX) {
401  h2xyROCHits[rocHistIndex][trocId]->Fill(rowROC,colROC);
402  h2xyROCadc[rocHistIndex][trocId]->Fill(rowROC,colROC,adc);
403  ++HitsMultROC[rocHistIndex][trocId];
404  }
405  }
406  } //end if(RPindexValid[index]) {
407  }
408 
409  if(int(ds_digi.data.size()) > multHits) multHits = ds_digi.data.size();
410  } // end if(StationStatus[station]) {
411  } // end for(const auto &ds_digi : *pixDigi)
412 
413  for(int arm=0; arm<2; arm++) for(int stn=0; stn<NStationMAX; stn++)
414  for(int rp=0; rp<NRPotsMAX; rp++) {
415  int index = getRPindex(arm,stn,rp);
416  if(RPindexValid[index]==0) continue;
417  if(RPactivity[arm][rp]==0) continue;
418 
419  int np = 0;
420  for(int p=0; p<NplaneMAX; p++) if(HitsMultPlane[index][p]>0) np++;
422  if(np>5) hRPotActivBX[index]->Fill(event.bunchCrossing());
423 
424  int rocf[NplaneMAX];
425  for(int r=0; r<NROCsMAX; r++) rocf[r]=0;
426  for(int p=0; p<NplaneMAX; p++) {
427  int indp = getPlaneIndex(arm,stn,rp,p);
428  for(int r=0; r<NROCsMAX; r++) if(HitsMultROC[indp][r] > 0) ++rocf[r];
429  for(int r=0; r<NROCsMAX; r++) h2HitsMultROC[index]->Fill(p,r,HitsMultROC[indp][r]);
430  }
431  int max = 0;
432  for(int r=0; r<NROCsMAX; r++) if(max < rocf[r])
433  { max = rocf[r]; }
434 
435  for(int r=0; r<NROCsMAX; r++) hRPotActivROCs[index]->Fill(r,rocf[r]);
436  for(int r=0; r<NROCsMAX; r++) if(rocf[r] == max)
437  hRPotActivROCsMax[index]->Fill(r,max);
438 
439  if(max > 4) hRPotActivBXroc[index]->Fill(event.bunchCrossing());
440  }
441 
442  if((nEvents % 100)) return;
443  if(verbosity) LogPrint("CTPPSPixelDQMSource")<<"analyze event "<<nEvents;
444 }
445 
446 //--------------------------------------------------------------
448 {
449 }
450 
451 //-----------------------------------------------------------------------------
453 {
454  if(!verbosity) return;
455  LogPrint("CTPPSPixelDQMSource")
456  <<"end of Run "<<run.run()<<": "<<nEvents<<" events\n"
457  <<"mult Hits/Clus: "<<multHits<<" / "<<multClus
458  <<" cluSizeMaxData= "<<cluSizeMaxData;
459 }
460 
461 //---------------------------------------------------------------------------
463 
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:64
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
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
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