CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TdeECAL.cc
Go to the documentation of this file.
2 #include <bitset>
3 
6 //#include "DQM/EcalCommon/interface/Numbers.h"
9 
10 using namespace dedefs;
11 
13 
14  verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag",0);
15 
16  if(verbose())
17  std::cout << "L1TdeECAL::L1TdeECAL()...\n" << std::flush;
18 
19  DEsource_ = iConfig.getParameter<edm::InputTag>("DataEmulCompareSource");
20  histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1TEMU//ECALexpert/");
21 
22  dbe = NULL;
23  if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
24  dbe = edm::Service<DQMStore>().operator->();
25  dbe->setVerbose(0);
26  }
27 
28  histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
29  if(iConfig.getUntrackedParameter<bool> ("disableROOToutput", true))
30  histFile_ = "";
31 
32  if (histFile_.size()!=0) {
33  edm::LogInfo("OutputRootFile")
34  << "L1TEmulator ECAL specific histograms will be saved to "
35  << histFile_.c_str()
36  << std::endl;
37  }
38 
39  if(dbe!=NULL)
40  dbe->setCurrentFolder(histFolder_);
41 
42  hasRecord_=true;
43 
44  if(verbose())
45  std::cout << "L1TdeECAL::L1TdeECAL()...done.\n" << std::flush;
46 }
47 
49 
50 void
52 
53  if(verbose())
54  std::cout << "L1TdeECAL::beginJob() start\n";
55 
56  DQMStore* dbe = 0;
57  dbe = edm::Service<DQMStore>().operator->();
58  if(dbe) {
59  dbe->setCurrentFolder(histFolder_);
60  dbe->rmdir(histFolder_);
61  }
62 
63  if(dbe) {
64  dbe->setCurrentFolder(histFolder_);
65 
66  etmapData.reserve(nSM);
67  etmapEmul.reserve(nSM);
68  etmapDiff.reserve(nSM);
69  etmapData.resize( nSM, static_cast<MonitorElement*>(0) );
70  etmapEmul.resize( nSM, static_cast<MonitorElement*>(0) );
71  etmapDiff.resize( nSM, static_cast<MonitorElement*>(0) );
72 
73 
74  std::string lbl("");
75  char tmp[100];
76  for(int j=0; j<nSM; j++) {
77  lbl.clear();
78  sprintf(tmp, "etmapDataSM%d", j+1);
79  lbl+=tmp;
80  etmapData[j] = dbe->book3D(lbl.c_str(),lbl.c_str(),
81  nTTEta, 0, nTTEta,
82  nTTPhi, 0, nTTPhi,
83  256, 0, 256.);
84  sprintf(tmp, "etmapEmulSM%d", j+1);
85  lbl.clear(); lbl+=tmp;
86  etmapEmul[j] = dbe->book3D(lbl.c_str(),lbl.c_str(),
87  nTTEta, 0, nTTEta,
88  nTTPhi, 0, nTTPhi,
89  256, 0, 256.);
90  sprintf(tmp, "etmapDiffSM%d", j+1);
91  lbl.clear(); lbl+=tmp;
92  etmapDiff[j] = dbe->book3D(lbl.c_str(),lbl.c_str(),
93  nTTEta, 0, nTTEta,
94  nTTPhi, 0, nTTPhi,
95  256, 0, 256.);
96  }
97  lbl= "EcalEtMapDiff" ;
98  EcalEtMapDiff = dbe->bookProfile2D(lbl.c_str(),lbl.c_str(),
99  35, -17.5, 17.5,
100  72, -10., 350.,
101  256, 0, 256.);
102  lbl= "EcalFGMapDiff" ;
103  EcalFGMapDiff = dbe->bookProfile2D(lbl.c_str(),lbl.c_str(),
104  35, -17.5, 17.5,
105  72, -10., 350.,
106  2, 0, 2.);
107  }
108 
109  if(verbose())
110  std::cout << "L1TdeECAL::beginJob() end.\n" << std::flush;
111 }
112 
113 void
115  if(verbose())
116  std::cout << "L1TdeECAL::endJob()...\n" << std::flush;
117  if(histFile_.size()!=0 && dbe)
118  dbe->save(histFile_);
119  //tbd delete emap;
120 }
121 
122 
123 // ------------ method called to for each event ------------
124 void
126 
127  if(!hasRecord_)
128  return;
129 
130  if(verbose())
131  std::cout << "L1TdeECAL::analyze() start\n" << std::flush;
132 
135  iEvent.getByLabel(DEsource_, deRecord);
136 
137  if (!deRecord.isValid()) {
138  edm::LogInfo("DataNotFound")
139  << "Cannot find L1DataEmulRecord with label "
140  << DEsource_.label()
141  << " Please verify that comparator was successfully executed."
142  << " Emulator DQM for ECAL will be skipped!"
143  << std::endl;
144  hasRecord_=false;
145  return;
146  }
147 
148  bool isComp = deRecord->get_isComp(ETP);
149  if(!isComp) {
150  if(verbose())
151  std::cout << "[L1TdeECAL] Ecal information not generated in de-record."
152  << " Skiping event!\n";
153  return;
154  }
155 
156  int DEncand[2];
157  for(int j=0; j<2; j++)
158  DEncand[j] = deRecord->getNCand(ETP,j);
159 
160  if(verbose())
161  std::cout << "[L1TdeECAL] ncands"
162  << " data: " << DEncand[0]
163  << " emul: " << DEncand[1]
164  << std::endl;
165 
166 
168  L1DEDigiCollection deColl;
169  deColl = deRecord->getColl();
170 
171  if(verbose()) {
172  std::cout << "[L1TdeECAL] digis: \n";
173  for(L1DEDigiCollection::const_iterator it=deColl.begin(); it!=deColl.end(); it++)
174  if(it->sid()==ETP)
175  std::cout << "\t" << *it << std::endl;
176  }
177 
178 
180 
182 
183  // d|e candidate loop
184  for(L1DEDigiCollection::const_iterator it=deColl.begin();
185  it!=deColl.end(); it++) {
186 
187  int sid = it->sid();
188  int cid = it->cid();
189 
190  if(sid!=ETP)
191  continue;
192 
193  if(it->empty())
194  continue;
195 
196  assert(cid==ECALtp);
197 
198  if(verbose())
199  std::cout << "[L1TdeECAL] processing digi: \n\t"
200  << *it << "\n" << std::flush;
201 
202  //get (global) tt coordinates
203  int iphi = (int)it->x1();
204  int ieta = (int)it->x2();
205 
206  //get sm id
207  int ism = iEtaiPhiToSMid(ieta,iphi); //1..36
208 
209  //get local indices
210  int zside = (ieta>0?1:-1);
211  int iet = abs(ieta);
212  int ipt = iphi;
213  ipt = ipt + 2;
214  if ( ipt > 72 ) ipt = ipt - 72;
215  ipt = (ipt-1)%4 + 1;
216  if ( zside > 0 ) ipt = 5 - ipt;
217 
218 
220  EcalTrigTowerDetId idt(zside, EcalBarrel, abs(ieta), iphi);
221  // ... from EcalElectronicsMapping (needs addt'l lib)
222  //int itt = map.iTT (idt); //1..68
223  int itcc = emap.TCCid(idt); //37..54(eb+) 55..72(eb-)
224  // need here converter tcc->sm id
225  int smid = TCCidToSMid(itcc);
226  // ... or as in EBTriggerTowerTask (needs addt'l lib)
227  //int ismt = Numbers::iSM( idt );
228 
229  if(verbose())
230  std::cout << "L1TdeECAL \t"
231  << " smid:" << smid
232  << " ism:" << ism
233  << " itcc:" << itcc
234  << " local phi:" << ipt << " eta:" << iet
235  << "\n" << std::flush
236  << *it
237  << "\n" << std::flush;
238  if(ism!=smid)
239  LogDebug("L1TdeECAL") << "consistency check failure\n\t"
240  << " smid:" << smid
241  << " ism:" << ism
242  << " itcc:" << itcc
243  << std::endl;
244 
245  float xiet = iet+0.5;
246  float xipt = ipt+0.5;
247 
248  //get energy values
249  float rankarr[2];
250  it->rank(rankarr);
251  // get FG values
252  unsigned int raw[2] ;
253  it->data(raw) ;
254  int FG[2] = { (raw[0] & 0x1000000)!=0, (raw[1] & 0x1000000)!=0 } ;
255 
256  int type = it->type(); //3 data only, 4 emul only
257  if(type!=4 && etmapData[ism-1])
258  etmapData[ism-1]->Fill(xiet-1, xipt-1, rankarr[0]);
259  if(type!=3 && etmapEmul[ism-1])
260  etmapEmul[ism-1]->Fill(xiet-1, xipt-1, rankarr[1]);
261  if(type<2 && etmapDiff[ism-1]) {
262  float diff = fabs(rankarr[0]-rankarr[1]);
263  etmapDiff[ism-1]->Fill(xiet-1, xipt-1, diff);
264  float phi = iphi ;
265  if (phi>70) phi -= 73 ;
266  phi *= 5 ;
267  if (phi>0) phi -= 5 ;
268  EcalEtMapDiff->Fill(ieta, phi, diff) ;
269  diff = fabs(FG[0]-FG[1]);
270  EcalFGMapDiff->Fill(ieta, phi, diff) ;
271  }
272  }//close loop over dedigi-cands
273 
274 
275  if(verbose())
276  std::cout << "L1TdeECAL::analyze() end.\n" << std::flush;
277 
278 }
279 
280 // in :: iphi 1..72 [71,72,1..70]
281 // ieta -17..-1 (z-) 1..17 (z+)
282 // out :: SMid 19..36 (z-) 1..18 (z+)
283 int L1TdeECAL::iEtaiPhiToSMid(int ieta, int iphi) {
284  // barrel
285  int iz = (ieta<0)?-1:1;
286  iphi += 2;
287  if (iphi > 72) iphi -= 72;
288  const int kEBTowersInPhi = 4; //EBDetId::kTowersInPhi
289  int sm = ( iphi - 1 ) / kEBTowersInPhi;
290  if ( iz < 0 )
291  sm += 19;
292  else
293  sm += 1;
294  return sm;
295 }
296 
297 // in :: TCCid 37..54 (z-) 55..72 (z+)
298 // out :: SMid 19..36 (z-) 1..18 (z+)
299 int L1TdeECAL::TCCidToSMid(int tccid) {
300  // barrel
301  if ( tccid>37-1 && tccid<54+1) return tccid-37+19;
302  else if ( tccid>55-1 && tccid<72+1) return tccid-55+ 1;
303  else return 999;
304 }
#define LogDebug(id)
type
Definition: HCALResponse.h:22
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: L1TdeECAL.cc:125
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2311
MonitorElement * book3D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ)
Book 3D histogram.
Definition: DQMStore.cc:776
#define abs(x)
Definition: mlp_lapack.h:159
#define NULL
Definition: scimark2.h:8
std::vector< L1DataEmulDigi > L1DEDigiCollection
Definition: DEtrait.h:79
int TCCid(const EBDetId &id) const
returns the TCCid of an EBDetId
int iEvent
Definition: GenABIO.cc:243
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
L1TdeECAL(const edm::ParameterSet &)
Definition: L1TdeECAL.cc:12
~L1TdeECAL()
Definition: L1TdeECAL.cc:48
virtual void beginJob(void)
Definition: L1TdeECAL.cc:51
int TCCidToSMid(int)
Definition: L1TdeECAL.cc:299
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual void endJob()
Definition: L1TdeECAL.cc:114
int iEtaiPhiToSMid(int, int)
Definition: L1TdeECAL.cc:283
tuple cout
Definition: gather_cfg.py:41
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: DDAxes.h:10
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:972